Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question for Ginny

122 views
Skip to first unread message

Martin

unread,
May 8, 2013, 7:04:29 AM5/8/13
to
Hello Ginny

I am testing out your comms library

Your sample does not error. But my code (based on yours) is getting
error 87 SetCommState failed in SetProtcol. tested on 2 different PCs.

I am setting up the serial in a method then passing it back to the screen.

Any ideas please?

Thanks

Martin

METHOD StartComms (nPort) CLASS ScannerScreen

LOCAL oComm AS Serial, ;
oMain AS MainWindow, ;
nBaud AS DWORD, ;
nPar AS BYTE, ;
nLen AS BYTE, ;
nStop AS BYTE, ;
cErr AS STRING, ;
cPort AS STRING, ;
oComI AS ComINI

cPort := 'Com'+Str(nPort,1)


oMain := SysObject()
oComI := oMain:ComINIFS

oComm := Serial{SELF:Handle()}
oComm:Open(cPort)
DO CASE
CASE nPort = 1
nBaud := oComI:Com1Baud
nPar := oComI:Com1Par
nLen := oComI:Com1Len
nStop := oComI:Com1Stop
CASE nPort = 2
.............
.............
ENDCASE

oComm:Baud := nBaud
oComm:Parity := nPar
oComm:ByteSize := nLen
oComm:StopBits := nStop

IF !oComm:SetProtocol()
cErr := oComm:ErrorDesc
Hit_Key('Unable to open '+cPort+CRLF+;
'Error Text '+oComm:ErrorDesc+CRLF+;
'Error Code '+oComm:ErrorCode,'Communication Setup Error')

oComm:Close()
BREAK
ENDIF
// Start receiving comm events in the MLE
oComm:EnableEvents(EV_RXCHAR)

RETURN oComm

Martin

unread,
May 8, 2013, 7:15:03 AM5/8/13
to
This line causes the error
oComm:StopBits := nStop

nStop is a byte with a value of 1

Looks like one stop bit is 0!

Aghhhhhhhhhh!!!!!!!!!!!!

Ginny Caughey

unread,
May 9, 2013, 7:13:53 AM5/9/13
to
Stopbits are a bit strange. Here's code from my serial tester that works:

oDevice:StopBits := IIF(oCCZeroButton:Checked, 0, 2)

Let me know if you need my tester code. It uses ClassMate but I'm including
the BeginButton code here so you can see how it works:

METHOD BeginButton() CLASS CommWindow
LOCAL cErr AS STRING
LOCAL dwBaud, dwParity AS DWORD
LOCAL cPort AS STRING
LOCAL oDevice AS Serial

oDevice := oDCCommEdit:Device

// Set the comm MLE to empty again
oDCCommEdit:TextValue := ""
oDCCommEdit:SetFocus()

BEGIN SEQUENCE
// Set comm port with values from the window's controls
cPort := oDCPortListBox:CurrentItem
IF !oDevice:Open(cPort)
cErr := "Cannot open port "+oDCPortListBox:CurrentItem + CRLF+ ;
"Error code "+oDevice:ErrorCode+": "+oDevice:ErrorDesc
BREAK
ENDIF

// Set timeout values for read
//oDCCommEdit:Device:ReadIntervalTimeout := MAXDWORD
oDevice:ReadIntervalTimeout := 0 // Disable read interval
timeouts
oDevice:ReadTimeoutMultiplier := 500
oDevice:ReadTimeoutConstant := 1000
oDevice:WriteTimeoutMultiplier := 0
oDevice:WriteTimeoutConstant := 1000
IF !oDevice:SetTimeOut()
cErr := "Can't set timeout values for scale port"
BREAK
ENDIF

dwBaud := Val(oDCBaudListBox:CurrentItem)
oDevice:Baud := dwBaud
dwParity := oDCParityListBox:CurrentItemValue
oDevice:Parity := dwParity
oDevice:ByteSize := BYTE(IIF(oCCSevenButton:Checked, 7, 8))
oDevice:StopBits := IIF(oCCZeroButton:Checked, 0, 2)

IF !oDevice:SetProtocol()
cErr := oDevice:ErrorDesc
BREAK
ENDIF
// Start receiving comm events in the MLE
oDevice:EnableEvents(EV_RXCHAR)

// Disable Begin and Exit buttons and enable End button
oCCBeginButton:Enabled := FALSE
oCCExitButton:Enabled := FALSE
oCCEndButton:Enabled := TRUE

RECOVER
// Display error message
MessageBox(0, PSZ(cErr), PSZ("Error"), MB_OK)
END SEQUENCE

CLASS SerialMLE INHERIT MultiLineEdit
PROTECT oComm AS Serial // the serial object used by this MLE
EXPORT CancelRequested AS LOGIC

DECLARE ACCESS Device

Ginny



"Martin" wrote in message news:Lsqit.23306$sr.2...@fx09.fr7...

Martin

unread,
May 10, 2013, 9:16:34 AM5/10/13
to
Thanks Ginny - I managed to fix that. Just awaiting a new barcode gun
and cradle.

Currently examining 13 year old code for the processing engine
0 new messages