Reading Com Port (OpenInsight Specific)
At 25 MAY 1998 12:38:01PM Duane Pekse wrote:
I need to read the current status of a com port. I seem to remember seeing it in the manual once, but I can't find it now. I'm sure it's possible. Can anyone help me?
Duane Pekse, Developer
Aldata Software
At 28 MAY 1998 04:12AM Colin Rule (CSSP) wrote:
I don't know if the following code is of use.
We use it to communicate with a digitiser tablet.
There are many other procedures also, but this one may have what you need.
Sorry about the wrapping, Revtech should make the edit box resizable.
COMPILE SUBROUTINE COMM_ACCESS(MODE,COMM_PORT_HANDLE,COMMDATA)
* STANDARD
* Open/Close Comm port, Read/Write to port
* AG - May 96
*
DECLARE FUNCTION BLANK_STRUCT,GET_PROPERTY,STRUCT_TO_VAR,VAR_TO_STRUCTDECLARE FUNCTION OpenComm,CloseComm,BuildCommDCB,SetCommState,ReadComm,WriteCommBEGIN CASECASE MODE=OPEN" ;GOSUB OPEN_PORTCASE MODE=CLOSE" ;GOSUB CLOSE_PORTCASE MODE=READ" ;GOSUB READ_FROM_PORTCASE MODE=WRITE" ;GOSUB WRITE_TO_PORTEND CASERETURN
OPEN_PORT:
COMM_ERRORS="COMM_ERRORS=-1 ;COMM_ERRORS=Invalid or unsupported device"COMM_ERRORS=-2 ;COMM_ERRORS=Device already in use"COMM_ERRORS=-10;COMM_ERRORS=Device already in use"COMM_ERRORS=-12;COMM_ERRORS=Device baud rate is invalid"*
PORT =COMMDATABAUD_RATE=COMMDATADATA_BITS=COMMDATASTOP_BITS=COMMDATAPARITY =COMMDATA1,1FLOW_CONTROL=COMMDATA1,1PORT_SETTINGS=PORT:":":BAUD_RATE:",":PARITY:",":DATA_BITS:",":STOP_BITS:\00\PORT=PORT:\00\INQSIZE=1024;OUTQSIZE=128COMM_PORT_HANDLE=OpenComm(PORT,INQSIZE,OUTQSIZE)LOCATE COMM_PORT_HANDLE IN COMM_ERRORS USING @VM SETTING POS THENCOMM_PORT_HANDLE=COMM_ERRORSRETURNEND*
DCB_STRUCT=BLANK_STRUCT("DCB")RETVAL=BuildCommDCB(PORT_SETTINGS,DCB_STRUCT)COMM_PARAMS=STRUCT_TO_VAR(DCB_STRUCT,"DCB")BEGIN CASECASE FLOW_CONTROL=X"COMM_PARAMS=3CASE FLOW_CONTROL=H"COMM_PARAMS=5COMM_PARAMS=9COMM_PARAMS=64END CASEDCB_STRUCT=VAR_TO_STRUCT(COMM_PARAMS,"DCB")RETVAL=SetCommState(DCB_STRUCT)RETURN
CLOSE_PORT:
RETVAL=CloseComm(COMM_PORT_HANDLE)RETURN
READ_FROM_PORT:
BUFF_LEN=50COMMDATA=STR(\00\,BUFF_LEN)RETVAL=ReadComm(COMM_PORT_HANDLE,COMMDATA,BUFF_LEN)COMMDATA=FIELD(COMMDATA,\00\,1)RETURN
WRITE_TO_PORT:
COMMDATA=COMMDATA:\00\BUFF_LEN=LEN(COMMDATA)RETVAL=WriteComm(COMM_PORT_HANDLE,COMMDATA,BUFF_LEN)RETURN
At 28 MAY 1998 04:50PM Duane Pekse wrote:
Thanks for the help. I have just one more question for you. Where did you find the OpenComm, CloseComm, etc Functions? Are they from a DLL, or are they part of OI? I couldn't find anything on them in the help file for OI, so I don't even have the prototype information.
Thanks again.
Duane
Aldata Software
At 29 MAY 1998 05:03AM Colin Rule wrote:
Sorry, forgot this.
It is a link to a DLL, all a bit tricky though.
I get my programmers to do this for me.
Hope this helps
Code below:
USER
*
* CSSP Functions Below
*
SHORT PASCAL OpenComm(LPCHAR,USHORT,USHORT)
SHORT PASCAL CloseComm(SHORT)
USHORT PASCAL EnableCommNotification(SHORT,USHORT,SHORT,SHORT)
SHORT PASCAL BuildCommDCB(LPCHAR,LPCHAR)
SHORT PASCAL GetCommState(SHORT,LPCHAR)
SHORT PASCAL SetCommState(LPCHAR)
SHORT PASCAL ReadComm(SHORT,LPCHAR,SHORT)
SHORT PASCAL WriteComm(SHORT,LPCHAR,SHORT)
At 01 JUN 1998 11:27AM Duane Pekse wrote:
Thanks a million for the info.
I think I've got it now.
Duane
At 15 JUL 1998 02:19PM Mike Hyslop wrote:
Colin,
Mike Hyslop here. I'm one of Duane Pekse's co-workers. A couple of months ago, you and he conducted an exchange of information concerning using OI to read and write to a com port.
The project has since fallen into my hands. I have been attempting to use the code segment you sent Duane, but I am missing a key element. I need to see what an actual call to the COMM_ACCESS subroutine looks like.
Specifically, what the COMMDATA argument looks like. Would yo be so kind as to send an example of a call to this subroutine, with the arguments included.
Thanks, in advance.
Best Regards,
Mike Hyslop, P.Eng.
Aldata Software Mgt. Inc.
email:[email protected]