I have an Arty A7 FPGA dev board. I have programmed it to read its on board power monitoring ADCs and send the results over UART to a PC app written in C#.
The FPGA samples the voltage monitor, then sends out the most significant byte, then sends out the least significant byte. Then it samples the current monitor, and sends out MSB then LSB.
On the PC side I press a button in the form, it discards everything currently in the receive buffer and then sends 't' to the FPGA which starts the capturing process.
To read from the FPGA I simply call _serialPort.ReadByte() four times, expecting to get sample 1 MSB, sample 1 LSB, sample 2 MSB, sample 2 LSB in that order. It seems I'm getting sample 2 MSB, Sample 2 LSB, sample 1 MSB, sample 1 LSB.
The data looks correct just using a serial monitor app, I used Terminal, so I don't think it's the FPGA side.
Is the serial input buffer not a FIFO style buffer?
Any help is appreciated, thanks!
Related
Hello dear programers I am trying to connect Avery weight G236 with PC over RS232.
But every time the weight retuns "insane".
">>6>>>\u0016\u0016\u0016>>6\u0016\u0016\u0016\u0016\u0016\u0016\u0016>\u0016\u0016\u0016>>"
My serial port configuration is (Baund rate 2400, Data bits 6, Stop bit two.). I tried to change these parameters but return was only "?" questioner or nothing.
Have someone any idea to solve this issue ?
I tried to solve issue related to scale serial-port comunication without any datasheet. It was random trying and configuring serial port in scale. Finally jdweng help my out. In coment wrote the most common settings for scales (my scale is Avery Weight-Tronix G236).
The normal default Baud Rate for a device is 9600, 8 bits, one stop bit.
On the end few informations about Avery Weight-Tronix scale settings:
How to show up menu ?
Hold PRINT button on the scale for few seconds
How to set serial-port comunication ?
Buttons SAMPLE = forward in menu, TARE - backward in menu, ZERO - confirm.
Try to find in settings menu mark SERIAL confirm with ZERO. In this submenu you can choose everithing related with serial-port comunication.
In my case (I couldn't find any manual from scale). I must choose broad which meanse the scale continuously sending weight to PC. It's not the best solution, but for my purpose it is enough.
I am currently working on a project where I need to control 16 pumps 1 stepper motor and 2 Distance sensors - 21 digital pins and 2 analog pins. I need to make a UI and have this use UI send information to the Arduino which will control my system. I would only need to receive 1 or 0 from each button press from the UI in order to determine which pump to needs to be turned on. I'm using an Arduino mega 2560 and coding the UI in Visual Studio C#.
I have done various research on serial communication for the Arduino, including using the serialevent() function and the firmata library. However I am having trouble understanding how all this ties together and if what I am wanting to do is even possible! Here are my questions:
Is this possible?
Is this possible by using Serialevent1()........... serialevent21()? or using Serial.availble() and Serial.read()
Instead of reading one button click on the UI at a time. Can the inputs on the UI be collected and sent to the arduino as a group. Then have the UI restart and clear out the values.
Any information and/or advice will help! I just need to be pointed in the correct direction!
Thanks
DG
Have you considered the following article?
It uses a Arduino mega 2560 and the article provides both the c# code and the Arduino code.
It communicates over the serial port and sends data in both directions.
Yes it is
The article above uses the Serial.print and readSerialInputCommand which is similar to Serial.read. You can use Serial.Read instead if you wish as it performs the same task and returns a different datatype.
You can compile the values into a group. If you want to be super optimized you can use bit-wise operators and compile the first 21 pin values into a byte array and send it.
However since its only 21 digital pins I recommend just using a string with the each character in the string linked to a pin. Eg: "10110" could set pin0, pin2, pin3 HIGH and set pin1, pin5 LOW.
I would recommend not restarting your UI as it will need to reconnect to serial port. Rather just clear all the values with your code.
I am Tommaso and I have just signed up.I would like to open a new this discussion hoping it could be interesting.
I am working with thermal camera(C# ,Visual studio 2012,windows 7 -x64) and I have already create a server that performs the following task:
Get raw frame from camera
Eventually rotation
Convert raw pixel value to Kelvin
Calculate min , avg and max pixel in a frame
Check temperature alert ,alarm.
Now I am asked to allow 4 work stations to see the real time thermal frames stream from cameras. Unfortunately in this project these are located in a real wide area at many meters (600-700 m) from main server. At 3,75 frame/s, frame resolution of 640x512 pixel and pixel depth of 14 bit (16) we are talking about 2,5Mbyte per second. No compression is provided.
So I decide to use the frames arrived at the server creating a socket to listen for 1 or 4 work stations need the stream. So each time a client connects, I create a dedicate queue where the main thread enqueues frames and where the socket thread dequeues and sends them to the connected client.
Here is my question: Due to importance of a single frame do you suggest to use the reliable and heaviest TCP or a the simplest UDP considering the amount of flow?
Sorry for my prolixity but it's just for an explanation .
If you want to know more about my project please ask .
Tommaso
You want to stream video. If a frame doesn't reach to it's destination, there would be no problem. Because after 250ms (I'll assume your video is 4 fps) another frame will be sent. Since every frame is not viral, you better use UDP.
I have an Arduino mega communicating over Bluetooth (bluesmirf gold device) to a C# application that I wrote. The Arduino is constantly sending a serial signal of 32 characters, the first always being an "S" and the last an "E". Using putty I can confirm that this signal is being sent correctly 99% of the time.
Now I want to read this signal with my C# application, which I am doing with the following code:
public string receiveCommandHC()
{
string messageHC = "";
if (serialHC.IsOpen)
{
while (serialHC.ReadChar() != 'S')
{
}
messageHC = serialHC.ReadTo("E");
serialHC.DiscardInBuffer();
}
return messageHC;
}
serialHC is of the serial class.
Sometimes this works perfectly but other times I'm having problems, I cannot find out why it works sometimes but others not.
The problem that I seem to be having is that sometimes I get a rather large Lag in the data that I am reading from the arduino. I notice this because I am sending button states and they only change a few seconds after I actually press or release the button on the Arduino. I used the standard baud rate of the Bluetooth device, which is 115200, and was wondering if changing that to a much lower rate could yield better results? What if any advantage would that have? I do not need hight communication rates, even updating the state 4-5 times a second would be acceptable for my application.
Is it possible the lag is coming from my code? I think it may be from the while loop that is waiting for the incoming "S" but then I don't see why it should hang there since there are new signals always coming in at a high rate.
I'm using the DiscardInBuffer() because I do not care about outdated data and just want to skip over that. It is much more important that I am reading current up to date data and acting on that fresh data.
Thank you for your help!
Best regards,
Bender
Update:
Just found out a bit more information while debugging. The problem only seems to appear:
When connected over Bluetooth (over USB cable there is absolutely NO Lag)
When a second Bluetooth connection is established from the PC to another device (different COM port and different baud rate)
Does anybody have any experience running two different devices off the same Bluetooth dongle on the PC? I can manage to connect to both no problem but still having the lag issue mentioned before.
Thanks for any help
You are not really using a physical serial port here. The BlueTooth driver merely emulates one. This is common, the Windows API has a well defined set of api functions to talk to a serial port. Emulating one makes the interface to the driver simple, the vendor doesn't have to supply an interface DLL or document a complicated DeviceIoControl() protocol.
Which means for one thing that the actual communication settings don't matter. Baudrate is meaningless in this scenario, it is the BlueTooth radio signaling that sets the transfer rate. The driver will accept whatever you select but will otherwise ignore it. Handshake signals might be interpreted, it's up to the driver to implement them. Communication error reporting is very rarely implemented, BlueTooth has an error correcting protocol, unlike a real serial port.
No, the loss of data here is entirely self induced. Clearly the driver does implement DiscardInBuffer(). Which accomplishes nothing but throw away any data that the driver received. This goes wrong if your code runs a bit late or gets interrupted by a thread context switch.
Delete the DiscardInBuffer() call.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I m trying to communicate with Kohler active meter. It s half duplex. I ve read all protocol. Kohler has own software to see the profiles. While it was reading the profiles, i tried to view how it is happening. Sending and recieving datas. Then i tried to write a programme in C#. To communicate in first steps baud-rate is chosen 300, and then it should be 4800.
Here is my problems:
If i try to debug my programme using F5, it is not communicating. But if i use step into mode F11, it is working? i guess it should wait some amount of time. any idea?
When i try to change baud-rate from 300 to 4800, step into mode F11 is not working. I checked in the software if it is changing or not, but it is fine. any idea what this is about?
This is a common mishap when you work with serial ports. They are very slow devices, especially at 300 baud. That's only one character per 33 milliseconds, an eternity on a modern machine. By using the debugger, you artificially slow down your program. A lot. Giving the serial port driver time to receive the full device response. When you run without single-stepping or breakpoints, the SerialPort.Read() call only returns one or a few characters at a time. You fix this by using ReadLine() with a properly set NewLine property or by storing the received bytes in a buffer until you got the full response.
You can't just change the baudrate, it must always match the rate of the device.
Before sending your requests wait for some time . When you debug with F5 you don't wait. But with F11 you wait unavoidablely. This also shows that your program works better when you wait :) Use a monitoring program like 'Free Serial Port Monitor' to find out these waiting times by first running Kohler's own program.
You can use a streamreader and streamwriter to communicate with the meter.
Like
writer = new StreamWriter(((System.IO.Ports.SerialPort)serialPort).BaseStream);
reader = new StreamReader(((System.IO.Ports.SerialPort)serialPort).BaseStream);
Don't forget to use writer.Flush() command just after you user write command.
To wait sometimes before you send your commands to the meter use System.Threading.Thread.Sleep(250); code . 250 is in msecs.
I don't recommend you to wait after sending the request. Wait before you send the new request, ACK message, etc.
If kohler's own program waits too much between commands set serialports timeout values ...
(serialport).ReadTimeout = xxx;
(serialport).WriteTimeout = xxx;
'Free Serial Port Monitor' this programme has really opened my mind. Thank you so much #ferda. and i solved the problem. it was about waiting times. First i saw the times for request and the answers using that programme. Then i also used Flush command. i watched my programme outputs using again FreeSerial Port Monitor programme. At the end i could send the datas and received datas at 4800 baud-rate. Just changing baud-rate in C# worked for Kohler. It doesn't need anything else.