Jump to content
giannis121

Com port & USB-ISS

Recommended Posts

giannis121

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: :(

Share this post


Link to post
Share on other sites
giannis121

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)

 

Share this post


Link to post
Share on other sites
Danyfirex

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

Share this post


Link to post
Share on other sites
giannis121

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)

 

Share this post


Link to post
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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.