Jump to content

Com port & USB-ISS


Recommended Posts

  • 1 month later...

I'm still trying to communicate with this device, but seems that I need some help.

#include <CommInterface.au3>

$hFile=_CommAPI_OpenCOMPort(2, 19200, 2, 8, 2)
if $hFile=0 Then MsgBox(0, "ERROR", @error)

_CommAPI_TransmitBinary($hFile, 0x5A)
_CommAPI_TransmitBinary($hFile, 0x01)

$data=_CommAPI_ReceiveBinary($hFile)

msgbox(0, "data", "data= " & $data)

_CommAPI_ClosePort($hFile)

I have a com-port monitor software and i can see that the data are transmitted,
put there is no any data received.

Normally I should receive 3 bytes, but there is no feedback.
Do I miss the sequence?
I need some help, if anyone has used the comport functions.

I also tried the UDF from this post, with the same luck: :(

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

If you have any idea, please share:

I should receive 3 bytes starting with the byte 0x07, but I am receiving only one byte (0x05).
(The program that i have from the manufacturer works fine.)

#include <CommInterface.au3>
#include <MsgBoxConstants.au3>


Local Const $iPort = 2
Local Const $iBaud = 19200
Local Const $iParity = 0
Local Const $iByteSize = 8
Local Const $iStopBits = 2

Local $hFile =_CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits)
_CommAPI_ClearCommError($hFile)
_CommAPI_PurgeComm($hFile)

_CommAPI_TransmitBinary($hFile, 0x5A)
_CommAPI_TransmitBinary($hFile, 0x01)

Local $sResult =_CommAPI_ReceiveBinary($hFile, 1, 0)

_CommAPI_ClosePort($hFile)

MsgBox($MB_SYSTEMMODAL, "Result:", $sResult, 5)

 

Link to comment
Share on other sites

Try a loop for wait a little. maybe the other date come later.

I mean something like this:

#include <CommInterface.au3>
#include <MsgBoxConstants.au3>


Local Const $iPort = 2
Local Const $iBaud = 19200
Local Const $iParity = 0
Local Const $iByteSize = 8
Local Const $iStopBits = 2

AdlibRegister("GetData",100)

Global $hFile =_CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits)
_CommAPI_ClearCommError($hFile)
_CommAPI_PurgeComm($hFile)

_CommAPI_TransmitBinary($hFile, 0x5A)
_CommAPI_TransmitBinary($hFile, 0x01)

While True
    Sleep(30)
WEnd

_CommAPI_ClosePort($hFile)


AdlibUnRegister("GetData")


Func GetData()
Local $sResult=0
$sResult=_CommAPI_ReceiveBinary($hFile, 1, 0)
if $sResult Then
    ConsoleWrite($sResult &  @CRLF)
EndIf
EndFunc

 

Saludos

Edited by Danyfirex
Set Code
Link to comment
Share on other sites

Danyfirex, thanks for the response.

I have some new details to share:
When I'm running the manufacturer's communication software, it works well.
If within a few seconds after closing this software, I'm running my code, I get the response I want from the device.
But only for one time.

So, seems to me that there's problem somewhere else, not on the transmit and receive function, although I don't get any @error message from the functions.
 

#include <CommInterface.au3>
#include <MsgBoxConstants.au3>

Local Const $iPort = 2
Local Const $iBaud = 19200
Local Const $iParity = 0
Local Const $iByteSize = 8
Local Const $iStopBits = 2

Local $hFile =_CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits)
if @error<>0 then
    msgbox(0, "Error", "Error: " & @error)
EndIf

_CommAPI_ClearCommError($hFile)
_CommAPI_PurgeComm($hFile)

_CommAPI_TransmitBinary($hFile, 0x5A)
_CommAPI_TransmitBinary($hFile, 0x01)

$sResult1 =_CommAPI_ReceiveBinary($hFile, 1, 0)
$sResult2 =_CommAPI_ReceiveBinary($hFile, 1, 0)
$sResult3 =_CommAPI_ReceiveBinary($hFile, 1, 0)

_CommAPI_ClosePort($hFile)

MsgBox($MB_SYSTEMMODAL, "Result:", $sResult1 & " " &$sResult2 & " " & $sResult3 , 5)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...