Sign in to follow this  
Followers 0
goldenix

[Solved]_Serial port communication example usage help

15 posts in this topic

#1 ·  Posted (edited)

Edit:

This topic was solved, see >Post #15 for the codes and setup that worked for me.

 

Hi

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')
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Run your code again, but set ConsoleWrite to:

ConsoleWrite($resOpen & "@error returns: " & @error)

This will give you a more detailed message on what the problem was on the failure of _CommSetport(). :)

Post it, and I'm sure we'll be able to help further. ;)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Run your code again, but set ConsoleWrite to:

ConsoleWrite($resOpen & "@error returns: " & @error)

This will give you a more detailed message on what the problem was on the failure of _CommSetport(). :)

Post it, and I'm sure we'll be able to help further. ;)

 

In not even sure Im using the code correctly. Its my first time programming serial communication. But hire is the return.

ConsoleWrite($resOpen & " @error returns: " & @error & @CRLF)
0 @error returns: 2
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

The error is happening with the $iStop as shown in the Returns from this UDF function _CommSetport():

Returns;  on success - returns 1 and sets $sErr to ''
;           on failure - returns 0 and with the error message in $sErr, and sets @error as follows
;                           @error             meaning error with
;                             1               dll call failed
;                             2               dll was not open and could not be opened
;                            -1               $iBaud
;                            -2               $iStop
;                            -4               $iBits
;                            -8               $iPort = 0 not allowed
;                           -16               $iPort not found
;                           -32               $iPort access denied (in use?)
;                           -64               unknown error

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

2               dll was not open and could not be opened

Yes I read that, but the question is why, I mean the example works & I copied the include code from there. So it should work....unless im missing code to make the communication work, Am I?

Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

It has to do with this line in the UDF that is returning an error of -2:

$vDllAns = DllCall($hDll, 'int', 'SetPort', 'int', $iPort, 'int', $iBaud, 'int', $iBits, 'int', $iPar, 'int', $iStop, 'int', $iFlow, 'int', $RTSMode, 'int', $DTRMode)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Looked at the udf & it says You cannot set the same COM port on more than one channel. Does it mean I need to create channel & then set port to the channel? 

confused.


My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

you can always try changing channels with _CommSwitch() like so:

_commSwitch(2)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This makes no sense, I started stripping code from example & if I drag & drop it into AutoIt3.exe, the example is working, but if I try to F5 run it GUI runs, but sending chars does not work. 

Weird things going on, + I also get this error, so I went & deleted byref in front of the

_CommSetPort($iPort, ByRef $sErr,

And guess what if I drag & drop it into autoit exe it works, but if I F5 it it does not work...

ERROR: _CommSetPort() called with Const or expression on ByRef-param(s).

EDIT: This issue with drag & dropping is solved, outdated autoit version was used to try to run this, working of final send code, will post it if it will work:

Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

 

This makes no sense, I started stripping code from example & if I drag & drop it into AutoIt3.exe, the example is working, but if I try to F5 run it GUI runs, but sending chars does not work. 

Weird things going on, + I also get

ERROR: _CommSetPort() called with Const or expression on ByRef-param(s).

Please post the script you used to get this error.


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thank you for support Breathe. Got everything working, guess all the problems were happening because of the outdated Autoit version.

Hire is the code that almost works for me, turns on the led by sending 1, then sleeping for 2 seconds & turning off the led by sending 0. It also returns the data that is transmitted back.

But it is still a bit bugged, if I look at the output data there should be : (Any ideas why that my be?)

Decimal value: 48

not 

Decimal value: 13

The code:

#include 'CommMG.au3';or if you save the commMg.dll in the @scripdir use #include @SciptDir & '\commmg.dll'

$resOpen = _CommSetPort(25, 0, 9600, 8, 0, 1, 0)
_CommSendstring(1 & @CR) ; Turn on led

While 1

    ;gets characters received returning when one of these conditions is met:
    ;receive @CR, received 20 characters or 200ms has elapsed
    $instr = _commGetLine(@CR, 20, 200);_CommGetString()

    If $instr <> '' Then;if we got something
        ;$instr = StringReplace($instr, @CR, @CRLF)
        ConsoleWrite($instr)
    Else
        Sleep(2000) ;MichaelXMike
        ExitLoop
    EndIf

WEnd

_CommSendstring(0 & @CR) ; turn off led
_Commcloseport(true)

Outputs Data that is returned back:

Decimal value: 49
Integer value: 1
Led is On
Decimal value: 13  // this should be 48 not 13, because 48 == 0 & in inputting 0
Integer value: -35
Invalid input, enter 1 or 0 to control led on pin 13!

Proper output that I expext to see:

Decimal value: 49
Integer value: 1
Led is On
Decimal value: 48
Integer value: 0
Led is Off
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

Glad you got it figured out, my pleasure. ;)

That seems like it would be something that is inside the arduino that would have to be configured.


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Glad you got it figured out, my pleasure. ;)

That seems like it would be something that is inside the arduino that would have to be configured.

 

With arduino software im getting proper values, with autoit not, But with autoit im sending:

_CommSendstring(1 & @CR) ; note the @cr

13 decimal is cr char

_CommSendstring("0") ; This does not work

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

Try

_CommSendString("0" & @CR)
_CommSendString(0 & @CR)

otherwise, someone with more knowledge is going to have to help you out with this one. I have reached my limit of comm knowledge. ^_^


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

I think this topic can be set as Solved. Hire are the results. Pretty neat actually, ill see if I can control a minirobot with hotkeys later.

Idea was to press the button, the led turns on & sends data to autoit script, press it again, led turns off (and sends data to autoit again.)

Btn went from off to on
Led is On
Btn went from off to on
Led is Off

Setup used: (that is a 10k resistor (a pulldown resistor), can be bigger)

IMG_0644_thumb.png

Arduino 1.0.6 code:

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int ledState = 0;
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);
  delay(50);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      Serial.println("Btn went from off to on");


      if(ledState == 0){
        digitalWrite(ledPin, 1); // Turn led on
        ledState = 1;

        Serial.println("Led is On");

      }
      else{
        digitalWrite(ledPin, 0);
        ledState = 0;
        Serial.println("Led is Off");
      }

    } 
    else {
      // if the current state is LOW then the button
      // wend from on to off:
      //Serial.println("wend from on to off");
    }
  }
  // save the current state as the last state, 
  //for next time through the loop
  lastButtonState = buttonState;
}

Autoit stripped gui code (stripped version of the example in the first post):

#include <GUIConstants.au3>
#include 'CommMG.au3';or if you save the commMg.dll in the @scripdir use #include @SciptDir & '\commmg.dll'
#include <GuiEdit.au3>
#include <windowsconstants.au3>
#include <buttonconstants.au3>

HotKeySet("{ESC}", "alldone")

#Region ### START Koda GUI section ### Form=d:\my documents\miscdelphi\commg\ExampleComm.kxf
$Form2 = GUICreate("COMMG Example", 473, 349, 339, 333, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit1 = GUICtrlCreateEdit("", 10, 25, 449, 223, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL))
$BtnSend = GUICtrlCreateButton("Send", 380, 273, 53, 30, $BS_FLAT)
$Input1 = GUICtrlCreateInput("1", 18, 279, 361, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Add LF to incomming CR", 273, 4, 145, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$Label11 = GUICtrlCreateLabel("Text to send", 24, 261, 63, 17)
$BtnSetPort = GUICtrlCreateButton("Set Port", 16, 312, 73, 30, $BS_FLAT)
$Label21 = GUICtrlCreateLabel("Received text", 34, 6, 70, 17)
$Label31 = GUICtrlCreateLabel("commg.dll version unknown", 272, 328, 135, 17)
GUICtrlSetColor(-1, 0x008080)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

   $resOpen = _CommSetPort(25, 0, 9600, 8, 0, 1, 0)
   _CommSetXonXoffProperties(11, 13, 100, 100)

    Opt("GUIOnEventMode", 1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
    GUICtrlSetOnEvent($BtnSend, "SendEvent")

While 1
    ;sleep(40)
    ;gets characters received returning when one of these conditions is met:
    ;receive @CR, received 20 characters or 200ms has elapsed
    $instr = _commGetLine(@CR, 20, 200);_CommGetString()

    If $instr <> '' Then;if we got something
        If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $instr = StringReplace($instr, @CR, @CRLF)
        GUICtrlSetData($Edit1, $instr, 1)
    Else
        Sleep(20) ;MichaelXMike
    EndIf

WEnd


Func _exit()
    Exit
EndFunc   ;==>justgo

Func SendEvent();send the text in the inputand append CR
   ; _CommSendstring(GUICtrlRead($Input1) & @CR)
    _CommSendstring(GUICtrlRead($Input1))
    GUICtrlSetData($Input1, '0');clear the input
    ;GUICtrlSetState($edit1,$GUI_FOCUS);sets the caret back in the terminal screen
EndFunc   ;==>SendEvent

NoGui example:

#include 'CommMG.au3'

$resOpen = _CommSetPort(25, 0, 9600, 8, 0, 1, 0)
_CommSendstring("1")
sleep(2000)
_CommSendstring("0")

And No gui port listener example: (this will give you the gui is off or on messages)

#include 'CommMG.au3'

$resOpen = _CommSetPort(25, 0, 9600, 8, 0, 1, 0)

While 1
    ;gets characters received returning when one of these conditions is met:
    ;receive @CR, received 20 characters or 200ms has elapsed
    $instr = _commGetLine(@CR, 20, 200);_CommGetString()

    If $instr <> '' Then;if we got something
        ConsoleWrite($instr)
    Else
        Sleep(20) ;MichaelXMike
    EndIf
WEnd

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

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
Sign in to follow this  
Followers 0

  • Similar Content

    • cheeroke
      By cheeroke
      Hi all,
      I got this code and would like to be able to change Baud Rate and instead of sending character by character i would like to be able (if possible) to send whole string. But i don't know how to change it.
      I am taking input from file and processing whole line (this is done in FilesHandling.au3).
      To execute this i am just calling SendData("FileName", int) in "main" script.
      Any help very appreciated.
      #include <WinAPI.au3> #include <Array.au3> #include "FilesHandling.au3" ;init DLL function, we need handle to call the function $h = DllCall("Kernel32.dll", "hwnd", "CreateFile", "str", "\\.\COM19", "int", BitOR($GENERIC_READ,$GENERIC_WRITE), "int", 0, "ptr", 0, "int", $OPEN_EXISTING, "int", $FILE_ATTRIBUTE_NORMAL, "int", 0) $handle=$h[0] Func SendData($FileName, $LineNumber) ;string to be send $c = readFile($FileName, $LineNumber) $cLenght = StringLen($c) $aArray = StringSplit($c, "") ;_ArrayDisplay($aArray, "", Default, 64) For $i = 1 To $cLenght writeChar($handle, $aArray[$i], $cLenght) Next ;move to next line writeChar($handle, @CR,1) EndFunc ;write a single char func writeChar($handle,$c,) $stString = DLLStructCreate("char str") $lpNumberOfBytesWritten = 0 DllStructSetData($stString, 1, $c) $res = _WinAPI_WriteFile($handle, DllStructGetPtr($stString, "str"), 1,$lpNumberOfBytesWritten) if ($res<>true) then ConsoleWrite ( _WinAPI_GetLastErrorMessage() & @LF) EndIf EndFunc  
    • SAM1386
      By SAM1386
      Hello,
      I can easily find my modem comport number using the code below:-
       
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3>    Global $key = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM","\Device\ssudmdm0000")     Local $iError = 0     If @error Then        ; The server is probably offline/port is not opened on the server.        $iError = @error         MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError)         Else         MsgBox($MB_ SYSTEMMODAL, "MODEM:", $key)         EndIf  
      but the thing is I am planning to design a small tool by which it can read the modem COM port and set the COM number and send AT command to modem port using UDF CommMG.au3 created by Martin. I added some below code to martins file :-
      ;====================================================================================================================== ;CommSendStandard,a new function for sending information to a serial port. ;====================================================================================================================== Func _CommSendStandard($port,$error,$command)    _CommSetPort($port,$error,9600,8,0,1,2)  if $error <> '' Then      MsgBox(262144,'Port Error = ',$error)  EndIf  _CommSendString($command & @CR) EndFunc   ;==>_CommGetLineStates ;=============================================================================================== After adding I wrote the below code for sending AT command to modem port but its not working.
      Please check the below code and let me know for the issue.
      ;===================================================================================== #include "C:\Program Files (x86)\AutoIt3\SciTE\CommMG.au3" #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3>    Global $key = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM","\Device\ssudmdm0000")     Local $iError = 0     If @error Then        ; The server is probably offline/port is not opened on the server.        $iError = @error         MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError)         Else         MsgBox($MB_SYSTEMMODAL, "MODEM:", $key)         EndIf Local $port=$key Local $porterror _CommSendStandard($port,$portError,"AT+CFUN=1,1") ;================================================================================================ but If I set the port number by my own in the code (for eg :- port number 8 or any value  instead of $key) it works fine and the modem gets reset.I want to know if there is any way to get the port number to a variable $port and discarding so that my above code works fine...In that case user donot have to take care of entering the port manually everytime and the script will automatically read the port number and set itself.
       
      Please help
       
      Regards,
      SAM
       
       
    • mikkokh
      By mikkokh
      Hi.
       
      I have several different devices connected to my desktop PC with USB COM adapters.
       
      Sometimes there is some error that will cut my USB COM device communication (usualy caused by lose USB connector)... After reconnecting that USB COM adapter, by some reason, Windows will give it different COM port number.
      I know there are some devices with integrated COM port circuit and they are used by client programs that can found them and only them by some USB hardware relate details and then use their COM port to communicate with correct COM device.
      It would be better to define some known and static hardware related string from device managers USB COM adapter details to my script config file, than always redefine different COM port to it.
       
      How can I do this trick with autoit?
       
      I communicate COM devices with cfxUDF.au3 AutoIt UDF.
    • Satvik
      By Satvik
      Hi 
      I am trying to open a dll using DLLOpen, however everytime i try to do so the function fails and returns -1 result. 
      I have the dll in the same folder as the auto it script. 
      Local $hDLL = DllOpen("C:\Users\310255155\Downloads\COMMGvv2\commg.dll") DllCall($hDLL, "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0) DllClose($hDLL) MsgBox(0,'result',$hDLL)  
    • dainiusb
      By dainiusb
      So I'm trying to send a string of data to Arduino using CommMG UDF. It seems that Arduino is not receiving it. I used Device Monitoring Studio and it shows that the data is sent fine and looks exactly the same as if I sent it from Arduino Serial Monitor. Is CommMG compatible with USB?
      Global $CMPort = 9 Global $CmBoBaud = 9600 Global $sportSetError = '' Global $CmboDataBits = 8 Global $CmBoParity = "none" Global $CmBoStop = 1 Global $setflow = 2 _CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow) If @error Then MsgBox(16,"Error!","Can't connect to Arduino on port - "&$CMPort) Exit EndIf _CommSetRTS(0) _CommSetDTR(0) _CommSendString("x" & 128 & "y" & 256 & "e", 1)