giannis121 Posted April 21, 2015 Posted April 21, 2015 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
Allow2010 Posted April 21, 2015 Posted April 21, 2015 i can recommend this https://www.autoitscript.com/wiki/CommAPI using it much, its easy and solid
giannis121 Posted June 16, 2015 Author Posted June 16, 2015 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:
giannis121 Posted July 6, 2015 Author Posted July 6, 2015 i can recommend thishttps://www.autoitscript.com/wiki/CommAPIusing it much, its easy and solidAllow2010, there should be one function called _CommAPI_TransmitData, but there is no in the CommInterface.au3 file.Am I right?
giannis121 Posted July 22, 2015 Author Posted July 22, 2015 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)
Danyfirex Posted July 22, 2015 Posted July 22, 2015 (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 July 22, 2015 by Danyfirex Set Code Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
giannis121 Posted July 30, 2015 Author Posted July 30, 2015 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now