Jump to content

Recommended Posts

Martin it works, i need to make some changes on the code. I use some part of your code.

The final code:

Func SendEvent();send the text in the inputand append CR
    dim $recbuf[3],$macadress[4],$i,$x,$y = 0

    For $x = 52 to 55
        _CommSendByte(255) 
        _CommSendByte(2)
        _CommSendByte(254)
        _CommSendByte($x)   
        For $i = 0 To 2
            If _CommGetInputCount() = '0' Then
                Sleep(300)
                If _CommGetInputCount() = '0' Then
                    MsgBox(0, 'ERROR ', 'No data after 300mS')
                Exit
                EndIf
            Else   ;either an error or data available
                If @error = 1 Then
                MsgBox(0, 'Error', 'Failed to call _CommGetInputCount')
                Exit
                EndIf
            EndIf
            $recbuf[$i] = _CommReadByte(0)
        Next
        If $recbuf[0] = 6 Then 
            $macadress[$y] = Hex($recbuf[2],2)
            $y = $y + 1
        EndIf
    Next
    If @error <> 0 Or  $recbuf[0] = -1 Then
        MsgBox(0, 'Resultado', 'Erro')
    Else
        MsgBox(0, 'Resultado', 'Ok')
        $received = _ArrayToString ($macadress," ") 
        GUICtrlSetData ($valor,$received)   
    EndIf
    
EndFunc

Taking out the _CommGetInputCount it needs to run two times to get the right values.

Thanks.

Bruno

Share this post


Link to post
Share on other sites

The above sounded like the problem I'm having. Great UDF btw martin, thanks.

Anyways, here's what I'm experiencing:

Connect my serial device,

run your example script (it works),

close the example,

run it again and the communications do not work.

if I close the example, the devices' lights blink (telling me the connection was closed).

when I run the example again, it works.

It seems to only close the connection every other time.

I thought it was only my code but as I said, the same happens with your example script.

Have you heard anyone else having this problem? I have only tried this 1 device so I definately won't rule it out but when it works, (every other time) it works great.

I've tried adding a sleep to the _comcloseport function but it didn't help.

If it helps, here is the documentation:

http://www.pioneerelectronics.com/PUSA/Sup...0.Support?tab=E

Edit: I am able to get it to work every time I run the script IF I change the COM port to 2 then back to 1

Edited by Teldin

Share this post


Link to post
Share on other sites

The above sounded like the problem I'm having. Great UDF btw martin, thanks.

Anyways, here's what I'm experiencing:

Connect my serial device,

run your example script (it works),

close the example,

run it again and the communications do not work.

if I close the example, the devices' lights blink (telling me the connection was closed).

when I run the example again, it works.

It seems to only close the connection every other time.

I thought it was only my code but as I said, the same happens with your example script.

Have you heard anyone else having this problem? I have only tried this 1 device so I definately won't rule it out but when it works, (every other time) it works great.

I've tried adding a sleep to the _comcloseport function but it didn't help.

If it helps, here is the documentation:

http://www.pioneerelectronics.com/PUSA/Sup...0.Support?tab=E

I don't know why this happens with your device. I haven't ben able to download the documentation you gave a link for because so far, amybe the site is too busy.

Have you tried using Hyerterminal or some terminal emulator? If so what happens with then?

Unfortunately, I cannot think of an explanation for why it should work every other time.

Can you tell me what version of AutoIt you are using?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I'm using 3.2.10 but you're right, it also seems to exhibit similar behavior with hyperterminal.

After more observation here's what seems to happen:

lights are off on the device,

run the script, no connection (commands don't work),

quit script which turn the lights on!?!,

run script again, commands work fine.

quit the script, lights turn off,

start at the beginning.

Weird. Why would it turn on only when I quit the script?

Here is the direct link to the pdf if you want to try it:

http://www.pioneerelectronics.com/pio/pe/i...0_RS232-CPM.pdf

Thanks for your time.

Share this post


Link to post
Share on other sites

I'm using 3.2.10 but you're right, it also seems to exhibit similar behavior with hyperterminal.

After more observation here's what seems to happen:

lights are off on the device,

run the script, no connection (commands don't work),

quit script which turn the lights on!?!,

run script again, commands work fine.

quit the script, lights turn off,

start at the beginning.

Weird. Why would it turn on only when I quit the script?

Here is the direct link to the pdf if you want to try it:

http://www.pioneerelectronics.com/pio/pe/i...0_RS232-CPM.pdf

Thanks for your time.

Have you tried sending some reset command to the player when it doesn't seem to respond? Of course if it isn't taking any notice of what is sent this won't help.

Have you tried connecting the cable as described in the manual here-

Some computers require the CTS port to be set to HIGH during communication. It is best to connect the CTS and DSR port on the computer to the DTR port on the player. During normal operation the players DTR is set to HIGH thus the unit is able to receive a command at any time.

I would not expect that this was needed if the handshaking is set to none, but it's worth trying, and there could always be an error in my dll, although I don't really see how it explains the every other time effect.

There is a function in my UDF called _CommSendBreak which was written for AutoitSteve but has never been tested. I would be interested to know if using this got communications working. Maybe _CommSendBreak(200,200), but this is clutching at straws because I don't see anything in the manual to suggest it will have any effect.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

The player does not respond to any commands (obviously) when it's not communicating with the PC, and there seem to be no reset commands to try anyway.

I'm not sure what CTS/DSR stuff their talking about, the port on the player is a 15 pin serial "Interface Connector" connecting to my 9pin PC COM1 port. Maybe that is the problem, I'm using the cable from a Percon scanner. I am assuming (and hoping!) because it works fairly well, that's not the problem :)

Anyways,

I tried:

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

But I just got E04 Errors without any command responces...(maybe a sleep was needed?)

What I did have some luck with is putting _CommClosePort() at the begging of the script. The device seems to behave a bit more predictably. it starts up and shuts down with the script. I still have to 'set port' twice, but I don't have to change the com port number anymore. I guess that's some progress.

Another interesting thing that may or may not be related,

When sending almost any command I first get a good responce, then an immediate error responce. See a log:

Command: ?R<CR> Response: E04 -----within 200ms - an error

Command: ?R<CR> Response: 01 ------correct responce to chapter request

Command: ?C<CR> Response: E04 -----within 200ms - an error

Command: ?C<CR> Response: 01 ------correct responce to title number request

Command: ?F<CR> Response: E04 -----within 200ms - an error

Command: ?F<CR> Response: 0007744 ----correct responce to frame number request

However, in reguards to a command which takes a second to two to complete (open, close the tray, etc.) I get the error first then I get an 'R' which means successful completion:

Command: OP<CR> Response: R

Command: OP<CR> Response: E04 ---immediately after sending OP command

According to the manual:

E04 - Feature not available - Non-Usable Function has been tried either the command mnemonic is wrong or or the command can not be used in this mode

I haven't taken a super close look at the UDF nor have I tried sniffing the COM port communications but could it be sending something the player does not recognize? If no then I guess the cable is the culprit...

Thanks again for all your help thusfar martin.

Edited by Teldin

Share this post


Link to post
Share on other sites

Well I found out why I was getting errors with each command. I was sending an additional <CR> with my command. I removed that and the errors are gone.

Also, is there a way to detect if any device is actually connected?

Edited by Teldin

Share this post


Link to post
Share on other sites

Well I found out why I was getting errors with each command. I was sending an additional <CR> with my command. I removed that and the errors are gone.

I'm glad there was a simple explanation.

Also, is there a way to detect if any device is actually connected?

If there is hardware handshaking you could send some characters and then check how many were still in the output buffer. Without hardware handshaking you could just send something and wait for a reasonable time for a reply. In your case if you send an invalid command you should get an error back. If no reply then no connection.

The level of some signals, such as DSR and CTS can indicate that a device is connected and ready, but I don't give you access to them in my dll.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

This UDF requires my comMG.dll which must be saved in either the script folder or the Windows folder.

It also requires GUIConstants.au3. How can i get it?

Share this post


Link to post
Share on other sites

It also requires GUIConstants.au3. How can i get it?

GuiConstants.au3 is in the includes for production 3.2.10.0 and Beta 3.2.11.1 AFAIK. It is planned to become redundant as described in the History section of the Help.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

That's great brendan! :) Thanks a lot for showing me the robots in action, I'm really pleased I've helped you to do that.

I assume the robots are independent of CD writers, is that correct? I like that you've got one robot feeding 2 devices. I suppose if you put them around in a circle one robot could feed maybe 8.

(I showed my wife but I had to prop her up because she kept falling asleep.)

Martin, just another update (though we talked about this a while back via email or PM, IIRC):

I distributed your DLL as part of an early version of my Universal Loader CLI a couple of months ago, which was released publicly as part of the the dbpoweramp R13 alpha/beta cycle (the code is in the driver set for the batch ripper modules). I've tested on some of my own 600 and 900 disc robots with very good success. Some other folks out there on the interwebs are now ripping 1000s of CDs hands-free with your little gem (and dbpoweramp, of course).

Meanwhile, I have to finish the work on the ULCLI, primarily to make it handle errors/problems encountered by the hardware and to enhance cooperation amongst processes serving a single robot. Then I'll unleash it on my own arena of robots.

Pperhaps I will call it...Ripperdome. :)

-brendan

Share this post


Link to post
Share on other sites

Martin, just another update (though we talked about this a while back via email or PM, IIRC):

I distributed your DLL as part of an early version of my Universal Loader CLI a couple of months ago, which was released publicly as part of the the dbpoweramp R13 alpha/beta cycle (the code is in the driver set for the batch ripper modules). I've tested on some of my own 600 and 900 disc robots with very good success. Some other folks out there on the interwebs are now ripping 1000s of CDs hands-free with your little gem (and dbpoweramp, of course).

Meanwhile, I have to finish the work on the ULCLI, primarily to make it handle errors/problems encountered by the hardware and to enhance cooperation amongst processes serving a single robot. Then I'll unleash it on my own arena of robots.

Pperhaps I will call it...Ripperdome. :)

-brendan

Thanks for the update Brendan, and congratulations on your success.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hello!

Troble, then use function _CommGetString()

For example, com rx data "TEMP=.(." or hex (54 45 4d 50 3d 00 28 fe)

use $rx = _CommGetString()

$rx = "TEMP=" or hex (54 45 4d 50 3d)

all char after chr(0x00) don't get

Why I can get full string?

Help me, please.

Share this post


Link to post
Share on other sites

Hello!

Troble, then use function _CommGetString()

For example, com rx data "TEMP=.(." or hex (54 45 4d 50 3d 00 28 fe)

use $rx = _CommGetString()

$rx = "TEMP=" or hex (54 45 4d 50 3d)

all char after chr(0x00) don't get

Why I can get full string?

Help me, please.

You cannot read nulls using the CommGetString function because a null indicates the end of a string.

You need to use _CommGetByte or use the _CommReadByteArray function.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Could someone show an example of _CommSendByteArray? How do you write the array to memory and pass the pointer?

Thanks!

Here's a simple example

$Numbytes1 = 16;say we have 16 bytes

$Struct1 = DllStructCreate("byte[" & $Numbytes1 & "]")

For $n = 1 To 16;put some random numbers in the struct
    DllStructSetData($Struct1, 1, Random(0, 255, 1), $n)
Next

;send the bytes
_CommSendByteArray(DllStructGetPtr($Struct1), $Numbytes1, 1)
if @error then MsgBox(0, 'ERROR', '_CommSendByteArrray failed')

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks for your help Martin!

I had to fiddle with code a bit to get it to work. One cool thing is that I can char as the array type and directly passing the entire string in one shot. It works pretty well, but I had to use the "align 1" command to get it to work. Without that it would output all kind of garbage on the serial line.

Thanks again. What a great UDF!

$LastPacketTx = $APIPacket
    $APIPacketLength = StringLen($APIPacket)
    
    
    _CommSwitch($Port)
    
    If _CommPortConnection() == '' Then
        Output("Error: Comm port error")
        Return
    EndIf   
    
    $ByteArray = DllStructCreate("align 1;char[" & string($APIPacketLength) & "]")              
    DllStructSetData($ByteArray, 1, $APIPacket)
    
;send the bytes
    _CommSendByteArray(DllStructGetPtr($ByteArray), $APIPacketLength,1)
    if @error then output('_CommSendByteArrray failed')

Share this post


Link to post
Share on other sites

Thanks for your help Martin!

I had to fiddle with code a bit to get it to work. One cool thing is that I can char as the array type and directly passing the entire string in one shot. It works pretty well, but I had to use the "align 1" command to get it to work. Without that it would output all kind of garbage on the serial line.

Thanks again. What a great UDF!

$LastPacketTx = $APIPacket
    $APIPacketLength = StringLen($APIPacket)
    
    
    _CommSwitch($Port)
    
    If _CommPortConnection() == '' Then
        Output("Error: Comm port error")
        Return
    EndIf   
    
    $ByteArray = DllStructCreate("align 1;char[" & string($APIPacketLength) & "]")              
    DllStructSetData($ByteArray, 1, $APIPacket)
    
;send the bytes
    _CommSendByteArray(DllStructGetPtr($ByteArray), $APIPacketLength,1)
    if @error then output('_CommSendByteArrray failed')
Glad you got that to work, and thanks for the note about the alignment. I don't recall having that problem when I wrote the functions and tested them, but I didn't actually try the example I gave you :D .

BTW, you can do this

$ByteArray = DllStructCreate("align 1;char[" & StringLen($APIPacket) & "]")

in AutoIt and it will create a string formatted correctly, although the more explicit way you did it is how you would do it if you were used to C I guess.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Can anybody help me, I am not a coder but I see that this UDF could do what I need, let me explain.

I have a CarPC and a valentine one radar that is interfaced to my PC and I would like to add GPS Geofence functionality to the radar.

The software for the CarPC plays .wav files every time there is an alarm and I would like to replace it with a blank .wav file for example every time I am near a supermarket the alarm goes off so I would like to set a perimeter and when I enter it have the regular wav file be replaced by a blank one.

Lets say if I create a master .txt file with the information when I don't want the alarm to go off the file should contain

latitude, longitude, radius, lenght of alarm silenced and alarm type separated by commas

1250.5101,24718.5201,0.0010,10000 ,X,K,KA,N

The autoit script will read the GPS information and when it finds a match within the range replace the wav file for 10 secs or so.

If anybody can help I will greatly appreciate it and give you credit in the CarPC community.

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

  • Similar Content

    • By Corleone221
      Hello All,
       
      How can I load  actual connect  Com Ports to combobox?
       
      Thanks.
       
      for example  this 3....(6,7,8)

       
       
    • 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  
    • 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
       
       
    • 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.
×
×
  • Create New...