629 posts in this topic
Why do I get: Error: Missing right bracket ')' in expression.
I have written an AutoIt program that communicates with a RFXCOM transciever to control my home. This program runs 24/7 and occasionally I get the following message in a modal window:
Line 6102 (File "C:\homecontrol\HC.exe"):
Error: Missing right bracket ')' in expression.
My program waits for an operator input. So I have lost control and I am not able to terminate the program and start it again. Since my program has only a few hundred lines the error must be in one of the libraries. My questions are:
What is causing this error?
How can I trap this error?
In which library is this error generated?
This are my includes:
In the code I have already an error trap:
$objErr = ObjEvent("AutoIt.Error","MyErrFunc")
[Solved]_Serial port communication example usage help
This topic was solved, see >Post #15 for the codes and setup that worked for me.
I downloaded the COMMGvv2.zip & CommgExample.au3 From >this topic.
Ran the example GUI with default parametres, in the Send text field entered number 1 & pressed Send button. Sending 1 as char worked, the LED on my Arduino Leonardo board went on, then I sent 0 & led went off, just the way I programmed the board.
But I can not figure out how to make a custom code, a little help would be appreciated. Please.
my port: COM 25 baud: 9600 data bits: 8 stop bits: 1 parity: 1 flow control: 0 MY code so far: (consolewrite returns 0)
#include <GUIConstants.au3> #include 'CommMG.au3';or if you save the commMg.dll in the @scripdir use #include @SciptDir & '\commmg.dll' $iPort = 25 ; COM 25 $sErr = 'errormsg' $iBaud = 9600 $iBits = 8 $iPar = 0 $iStop = 1 $iFlow = 0 $RTSMode = 0 $DTRMode = 0 $resOpen = _CommSetPort($iPort, $sErr, $iBaud, $iBits, $iPar, $iStop, $iFlow, $RTSMode, $DTRMode) ConsoleWrite($resOpen & @LF) _CommSendstring('1')
receiving binary data thru a serial port
This topic is a complement of therealhanuta´s >CommAPI - Serial and parallel communication with Windows API
I think these routines are great, as they are simple to use, and use windows API with NO DLL´s.
It is about tips in receiving binary data thru a serial port, including value 0 (=end of string**). I hope it can help someone..
To know about the UDF to read/write serial port, please refer to the above link, with focus at post #3 and over
First, what is a binary stream? As an example, a microcontroler (PIC) getting data thru ADC and sending the 2 adquired bytes straight thru serial, without any treatment.
Now supose the message has: 1 letter(A-Z) + 4 ADC values + 3 counters of anything (each one byte). Your message will arrive with 1 + 4 x 2 + 3 = 12 bytes (or as AU3 sees it, a "string" with 12 "chars").
$sResult = _CommAPI_ReceiveData($hFile) will have at $sResult a "string" with 12 "chars" ** besides the first one, all other chars have byte values. On them can exist even binary value 0. So, it´s vital that 0 be not interpreted as end of string by receiver (PC) now let´s separate the 1 + 4 + 3 = 8 fields field1= StringMid($sResult,1,1) ;this is just a characte rbetwen A-Z field2= ASC(StringMid($sResult,2,1)) ;LSB of the ADC value. First byte = LSBb, 2nd. byte = MSB field2= field2 + ASC(StringMid($sResult,3,1))*256 ;MSB of ADC => now field2 has LSB + MSB (betwen 0-65535) ;field3..5 are similar to field 2, just increase by one the start position in stringMid field6= ASC(StringMid($sResult,10,1)) ;now field6 a "number" betwen 0-255; ;field7-8 are similar to field 6, just increase by one the start position in stringMid ** - be carefull, as probably $sResult = _CommAPI_ReceiveData($hFile) will get just the chars avaiable at the moment of call, so a kind of test/loop will be necessary to get all them, something like
$sResult="" DO $sResult = $sResult & _CommAPI_ReceiveData($hFile) UNTIL stringLentgth($sResult) >= 12 Jose
** thanks Martin into explaining about hex (0) to be interpreted as end-of-string and not xoff.