jimg Posted April 12, 2013 Share Posted April 12, 2013 I'm trying to talk to a Bluetooth device paired to my desktop. When I pair it, it assigns COM12 as the output port. My Bluetooth radio is one of those tiny USB dongles. If I open a terminal emulator (putty.exe in my case), it opens fine, the "pairing" status bit on my device lights up, and it reacts appropriately to my typing "a" at the keyboard. If I run the following script, I get a windows crash message saying "AutoIt V3 Script has stopped working" when the _CommSendByte is called. The second message is not produced. #include <CommMG.au3> $result="" $portvalue=inputBox("Port Number","Port Number?") $port = _CommSetport($portvalue,$result,9600,8,0,1,0) msgbox(0,"$port",$port) $value=_CommSendByte("a",0) msgbox(0,"$value",$value) sleep(5000) Exit I've used CommMG for lots of other chores with no problem. Any suggestions? Link to comment Share on other sites More sharing options...
jimg Posted April 13, 2013 Author Share Posted April 13, 2013 I've tried both Win7 and XP, and both do the same thing (APPCRASH). The XP system uses a laptop built-in Bluetooth radio, so I don't think it's the dongle that's causing the problem. I did find a terminal emulator that allows me to send 8 bit values, and they work as expected, which at least lets me wrap up the device development, but that doesn't solve the need of generating the data with an AutoIt3 script. I've tried three different port monitor programs, and none of them work, so I'm not sure what I can try next. Any suggestions on how to find the problem myself? Link to comment Share on other sites More sharing options...
stormbreaker Posted April 13, 2013 Share Posted April 13, 2013 (edited) I have had previous users complaining of Martin's UDF not working for them (the problem was virtual COM ports). I expect this solution to work: #include <WinAPI.au3> Global $nBytes $RESULT = _WinAPI_CreateFile("\\.\COM12", 2, 4) If $RESULT = 0 then msgbox(16, "", "Port not available, please plug in your device") else $tBuffer = DllStructCreate("byte") DllStructSetData($tBuffer, 1, StringToBinary('a')) _WinAPI_WriteFile($RESULT, DllStructGetPtr($tBuffer), 1, $nBytes) _WinAPI_CloseHandle($RESULT) EndIf Hopefully, our dear MVP solves it in the next release. Edited April 14, 2013 by MKISH ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
jimg Posted April 14, 2013 Author Share Posted April 14, 2013 I'm not sure what to do with your little snippet of code? Sorry, but I'm a hardware guy! Link to comment Share on other sites More sharing options...
stormbreaker Posted April 14, 2013 Share Posted April 14, 2013 I guess you asked for assistance in writing 'a' to COM port no. 12. This snippet does that. Just plug-in your device. If COM12 exists, it will write 'a' to COM port 12. ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
jimg Posted April 14, 2013 Author Share Posted April 14, 2013 Thanks! Your snippet works just fine, and I think I should be able to integrate it into a script to send general data. I do need to receive characters as well - is there some good spot to learn how to do that? Link to comment Share on other sites More sharing options...
stormbreaker Posted April 15, 2013 Share Posted April 15, 2013 (edited) So, you want to read data from COM port now. OK, see this one: Just a little bit modification and you get what you want? I assume you have at least the basic knowledge of AU3, WINAPI and COM ports, since you are a 'Hardware guy'. muttley Edited April 15, 2013 by MKISH ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
jimg Posted April 15, 2013 Author Share Posted April 15, 2013 It's the WinAPI I know nothing about. I used to design high end graphic systems, so I'll point my few remaining brain cells in the WinAPI direction and see where I get. I was secretly hoping you'd just throw me a fish, but that's okay Link to comment Share on other sites More sharing options...
stormbreaker Posted April 15, 2013 Share Posted April 15, 2013 I was secretly hoping you'd just throw me a fish, but that's okay Oh dear, I threw a large fish to you, but then you have to just do a little bit of cooking/frying whatever (I'm a vegetarian). Ask me personally, even someone who just takes a peek at that post can modify the code according to his needs. I'm all done for now. By the way, could you point me as to how you used COM ports with Bluetooth. I have a USB bluetooth as well (the Microsoft one)? THANKS AND Good luck. ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
jimg Posted April 15, 2013 Author Share Posted April 15, 2013 I was hoping to leave the ports open while the script was running, but I can't seem to open the same port for write and read, so I guess I have to open, close, over and over again. Seems pretty clumsy, but whatever it takes... Link to comment Share on other sites More sharing options...
jimg Posted April 18, 2013 Author Share Posted April 18, 2013 Just to close the topic, the examples provided by MKISH for reading and writing also work for R/W access.e.g.: $RESULT = _WinAPI_CreateFile(".COM12", 2, 6) Link to comment Share on other sites More sharing options...
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