I bought a GPIO board that connects to my system via USB configured as a comm port (COM4). Trouble is that the board is setup to recieve individual commands for I/O port statusese. So you send "GI1" and it returns either a "0" or a "1". No vbcr is required to get reply. This is too much work so I cam up with a loop that polls each input. I thing there is a timing issue of some sort. There is another event that could be sending commands to so maybe a sync issue too.
I am having comm errors like this:
<table border="0" cellpadding="0" cellspacing="2" width="100%"><tbody><tr><td colspan="1" class="LOGDateTime0" align="left" nowrap="nowrap">3/28/2011 7:07:04 PM </td><td colspan="3" class="LOGType0" align="left"> Error </td><td colspan="8" class="LOGEntry0" align="left">In OpenComPort, error opening port: Unable to obtain a handle to the COM port</td></tr> <tr> <td colspan="1" class="LOGDateTime1" align="left" nowrap="nowrap">3/28/2011 7:07:04 PM </td><td colspan="3" class="LOGType1" align="left"> Error opening my com port </td><td colspan="8" class="LOGEntry1" align="left">Error: Unable to obtain a handle to the COM port</td></tr> <tr> <td colspan="1" class="LOGDateTime0" align="left" nowrap="nowrap">3/28/2011 7:07:04 PM </td><td colspan="3" class="LOGType0" align="left"> Warning </td><td colspan="8" class="LOGEntry0" align="left">Attempt to send to COM port 4, port is not open</td></tr> <tr> <td colspan="1" class="LOGDateTime1" align="left" nowrap="nowrap">3/28/2011 7:07:04 PM </td><td colspan="3" class="LOGType1" align="left"> Error </td><td colspan="8" class="LOGEntry1" align="left">Running script, script run or compile error in file: labo_inputs_check.txt-2147467261:Object reference not set to an instance of an object. in line 27 More info: Object reference not set to an instance of an object.</td></tr></tbody></table>
Basically this is my script...
sub main()
Dim Data
Dim Count
Dim e
hs.CloseComPort(CommPort)
e=hs.OpenComPort(CommPort,"9600,n,8,1",0,"","")
if e <> "" then
hs.writelog "Error opening my com port",e
end if
For Count = 1 to 8
hs.SendToComPort CommPort,"GI" & Count &vbcr
Do
Data = hs.GetComPortData(CommPort)
Loop While InStr(Data, "") = 0
'hs.CloseComPort(CommPort)
'hs.writelog "Comport data",Data
Select Case Data
Case 0
hs.SetDeviceStatus "x" & Count, 3 'is ON
Case 1
hs.SetDeviceStatus "x" & Count, 2 'is ON
Case Else
hs.writelog "Comport data error",Data
End Select
Next
end sub
Any pointers? Thanks in advance.
I am having comm errors like this:
<table border="0" cellpadding="0" cellspacing="2" width="100%"><tbody><tr><td colspan="1" class="LOGDateTime0" align="left" nowrap="nowrap">3/28/2011 7:07:04 PM </td><td colspan="3" class="LOGType0" align="left"> Error </td><td colspan="8" class="LOGEntry0" align="left">In OpenComPort, error opening port: Unable to obtain a handle to the COM port</td></tr> <tr> <td colspan="1" class="LOGDateTime1" align="left" nowrap="nowrap">3/28/2011 7:07:04 PM </td><td colspan="3" class="LOGType1" align="left"> Error opening my com port </td><td colspan="8" class="LOGEntry1" align="left">Error: Unable to obtain a handle to the COM port</td></tr> <tr> <td colspan="1" class="LOGDateTime0" align="left" nowrap="nowrap">3/28/2011 7:07:04 PM </td><td colspan="3" class="LOGType0" align="left"> Warning </td><td colspan="8" class="LOGEntry0" align="left">Attempt to send to COM port 4, port is not open</td></tr> <tr> <td colspan="1" class="LOGDateTime1" align="left" nowrap="nowrap">3/28/2011 7:07:04 PM </td><td colspan="3" class="LOGType1" align="left"> Error </td><td colspan="8" class="LOGEntry1" align="left">Running script, script run or compile error in file: labo_inputs_check.txt-2147467261:Object reference not set to an instance of an object. in line 27 More info: Object reference not set to an instance of an object.</td></tr></tbody></table>
Basically this is my script...
sub main()
Dim Data
Dim Count
Dim e
hs.CloseComPort(CommPort)
e=hs.OpenComPort(CommPort,"9600,n,8,1",0,"","")
if e <> "" then
hs.writelog "Error opening my com port",e
end if
For Count = 1 to 8
hs.SendToComPort CommPort,"GI" & Count &vbcr
Do
Data = hs.GetComPortData(CommPort)
Loop While InStr(Data, "") = 0
'hs.CloseComPort(CommPort)
'hs.writelog "Comport data",Data
Select Case Data
Case 0
hs.SetDeviceStatus "x" & Count, 3 'is ON
Case 1
hs.SetDeviceStatus "x" & Count, 2 'is ON
Case Else
hs.writelog "Comport data error",Data
End Select
Next
end sub
Any pointers? Thanks in advance.
Comment