giannis121

Com port & USB-ISS

7 posts in this topic

I need some information on how to start with com port communication.

Recently I bought a USB-ISS (it's a USB to I2C device: http://www.robot-electronics.co.uk/htm/usb_iss_tech.htm).

It's connected as Virtual COM port.

So, I need some help to start exchanging data with the device.

Can you help me start?

Giannis

Share this post


Link to post
Share on other sites



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

i can recommend this

https://www.autoitscript.com/wiki/CommAPI

using it much, its easy and solid

Allow2010, there should be one function called _CommAPI_TransmitData, but there is no in the CommInterface.au3 file.

Am I right?

Share this post


Link to post
Share on other sites

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

#6 ·  Posted (edited)

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

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