dwilches / Ardity

Assets for integrating Arduino and Unity (or Unity and any hardware that communicates over a COM port)
329 stars 62 forks source link

Problem reading output from device #2

Closed jakubgondek closed 7 years ago

jakubgondek commented 7 years ago

My device is based on USB-COM converter by FTDI CHip. Maker of the device (our inhouse electronics guy) assured me, that on command "@REL#1@" device should respond with "@REL#ON@", but nothing comes out of library. When sending "@REL#1@" the device does what it's supposed. How can I know what's the problem? Is there any other way, to recieve data from the device with the library?

dwilches commented 7 years ago

Have you tried with Putty to debug the communications protocol? If in Putty your device responds with "@REL#ON@" but not with SerialCommUnity, then it may be your device doesn't respond with a newline at the end of the response. Could you check if it is that?

jakubgondek commented 7 years ago

I'm quite new to the hardware layer :) I tried connecting to the device with Putty, but nothing happens. there is no prompt. When I set the wrong COM port, Putty says it cannot connect, but when I enter the correct one nothing happens.

dwilches commented 7 years ago

There will be no prompt, it doesn't work exactly as when you use Putty to connect to a Linux server where a shell welcomes you. In the case of COM ports, it will show an empty screen once connected, and everything you type in there will be forwarded to the COM port. So just go ahead and start typing your command. You will find out if you need to pass a newline or not, and how the returned data looks.

jakubgondek commented 7 years ago

Nothing happens when I write my command "@REL#1@", the device doesn't respond, nor behave like it should.

dwilches commented 7 years ago

If you selected "Serial" as the "Connection type" in Putty, and are using the correct COM port, then the problem may be the command you are sending. You may check the manual for that device to know what it actually expects, it may be it expects a new line at the end, a null character, or to have a prefix before sending the message.

jakubgondek commented 7 years ago

Putty is sending diffrent line endings than the one that my device is expecting, so it's not processing my messages. I don't have the time to diagnose it more - it's not key feature of my app :)

dwilches commented 7 years ago

OK, if you later need it, in Putty you can press Ctrl+J to send a line-feed, and Ctrl+M for a carriage return. So instead of pressing the ENTER key, you make any combination of those two.

jakubgondek commented 7 years ago

I'm trying to use SerialComm to retrieve data from barcode scanner. When I connect to it via Putty and scan a barcode the code appears on the screen. When I use included JustRead example, app succesfully connects to the device, but after scanning nothing shows up. What might be the problem? I'm using Datalogic Quickscan QD2430.

dwilches commented 7 years ago

Hi Jakub,

The Unity part of SerialCommUnity needs a '\n' at the end of each message your hardware sends, it's with that line terminator that it decides where a message ends. Are you sure your hardware is sending that? If not, then the code that reads from the COM port in Unity needs to be changed so it knows when a message ends.

That's the first reason I could think on top of my head about why the library doesn't work with your hardware.

You mentioned a JustRead example, is that an example for your specific hardware? I couldn't find it online to take a look to that device's protocol.

jakubgondek commented 7 years ago

You were right. It was all about the line terminator. I found this example: https://code.msdn.microsoft.com/windowsdesktop/SerialPort-brief-Example-ac0d5004#content with reading data by bytes and the data is read but it waits for the terminator to dispatch. Probably that was also the case with my previous question. By JustRead example I meant DemoSceneUserPoll_JustRead scene you provided.

dwilches commented 7 years ago

OK, in that case, it is all about changing the line of the library how to detect an end-of-message. For some devices, all messages are of a fixed length; in others, there is special char terminating the message (like a '#', '.', '\n', etc.).

Salma175 commented 7 years ago

I was able to send data to my USB Based Micro controller (Maple Mini) but can not receive data from it . Tested with the Demo scene DemoScene_AutoPoll from the package . Tested it on putty and it works fine was able to log the data recieved from Port .

Salma175 commented 7 years ago

Hey thanks solved it be enabling DtrEnabled flag .. which is by default set to false :-)

dwilches commented 7 years ago

Good to hear it's working :)