RS232 sending ETX, but machine not responding - c#

I am trying to setup a simple program to a Spellman power supply.
I have setup a serialport object and included a timer to try RS232 connection.
Serial port configuration:
COM4
9600 baud rate
8 data bit
One stop bit
No handshaking is needed for this device.
I am having an issue because I need to send a SPECIFIC string to the Spellman
which I was told this would work:
STX22,pETX
But this does not work, I get no response.
Here is the problem: I have seen other examples, where the Tx or transmit line sends, 22,p^L. The ^L is a special looking character that is smaller and raised. What is this character and how do I send it in C#?
It seems that little character is what I need instead of the ETX part of the string because the hardware responds back.
The cabling works fine -- I shorted the 2 and 3 wire and I get back exactly what I sent in my program.
I have also tried sending it all data in hex instead of ASCII string, and it also does not work.
I also tried using \0002 and \0003 in many different forms for STX and ETX, does not work. I just need to figure out this 22,p^L issue.
Also this 22,p^L I have only seen in LabVIEW programs.

Related

SpiDevice read, write and transfer

Playing with Windows IoT on a raspberry pi 3 and I am trying to communicate to an Adafruit RFM69HCW.
I have connected to the device via SPI and not matter what I do I can't seem to get the pi to read anything from the device registers.
The one thing I wanted to know is what exactly does SpiDevice.Read(), Write(), TransferSequential() and TransferFullDuplex() do?
I know the obvious basics but I am after the steps it performs for each function.
Reason I ask is because in the spec of the RF module it says when communicating you have to set the CS pin to low, send the command and then set the CS pin back to High. Does, for example, SpiDevice.Read() do this already?
I have been converting both an Arduino library and a Python Raspberry Pi code so I know about doing the Hard Reset first.
Link to the spec if anyone interested.RFM69HCW-V1.1.pdf
Reason I ask is because in the spec of the RF module it says when
communicating you have to set the CS pin to low, send the command and
then set the CS pin back to High. Does, for example, SpiDevice.Read()
do this already?
Yes, you are right. I test the SPIAccelerometer sample and get the following sequence diagram. The yellow line is chip select and the other is clock line. As you can see, when writing and reading the CS is set to low.(The wave shape is ugly because my scope has low performance.)

Intercept and modify USB packets

The project is as follows;
I would like to create an application that will be able to see packets going to a USB device. When a certain bit of data that is known is sent to the device, the returning data will be intercepted and modified before the application requesting it, gets it. I have used a USB sniffer to see the packets being sent and I know exactly what bits need to be changed. My two questions are;
Is this a possible software solution?
Will this have to be a hardware solution?
Additional Information –
The USB device uses a FTDI245R chip for communication. I know the VID and PID of the device.
I have experience programming in vb.net and C# but I have never done anything with USB
I would like the application to be able to have a number entered and changed to hex data and that is what would be sent to the device. The number being entered would be changed frequently.
Any input is appreciated.
It sounds to me like you want an upper filter driver to the FTDI driver. I don't know what class or type of device you are using or if it has a vendor specific driver or not, but here is a sample that shows how to create an upper filter to a vendor specific driver. This example uses the OSRUSBFX2 device and sample driver in the WDK, you'll want to change the code to work and interface with the FTDI driver instead.

Checking external hardware through serial port

In my code, I'm setting the following values:
public SerialPort comPort = new SerialPort();
comPort.PortName = portName;
The PortName can be COM17, for example.
Now if I've add two devices through my GUI, both on COM17, one will eventually throw an exception (Access to COM17 denied). Now I'd like to check which device is hooked on that COM-port so if my application recognises it, it can send commands through the port, or if it's not recognized, it'll disable the option in my GUI.
So, is there a way to get unique information from the COM-port which I can save in my database when it's being installed?
EDIT: To clarify, if the wrong device is hooked to that COM port (other than when I installed), I get an error. I catch that error so I know it's not the right one. But I'd rather like to know which device that might be. Say I've got 2 drivers DLL's included, 2 different devices, and somebody switched them up. Then my application could check and see the correct names, and therefore conclude it's only a matter of changing the COM-ports of the installed objects, instead of just throwing an error and saying the user has to reinstall.
This is going to depend on your hardware. If the devices attached will give a predictable and consistent response to a particular signal message, then you can use that to identify them. I do the same thing to figure out which COM port a piece of proprietary hardware is attached to. I iterate through all the COM ports and send a message that I know will give a particular response from the hardware. Which ever port gives me the expected result is the one with the hardware.

Serial communication write

I have written a simple c# app having functionality of serial
communication. I am using it to read and write to a device. The device
recognizes string commands. I am successfuly able to read from device
using this app. But peoblem is in writing(sending) commands to device.
I am simply using
if (serialPort.IsOpen == true)
{
serialPort.Write("Command1");
}
But my device does not respondes to it.
To check, I tried sending same command using hyperterminal to my
device and my device recognizes it and works perfectly.
Can anybody guide me whats the accurate way to write or what
needs to be make sure for writing to serial port in c#. Is this encoding issue...
(Serial Read using this same app is working pretty fine !!)
Thank you for your time.
Moreover, there is no exception or error and in debug mode
this line executes.
This is a very common problem and invariably caused by leaving the Handshake property set to None. Serial port devices almost always pay attention to the handshake signals and ignore anything you send if the DTR signal isn't turned on. Which indicates that you are powered up and the data it receives isn't noise. Setting DtrEnable to true will be required, that's what HyperTerminal does as well.
And it won't send anything back when it thinks you are not ready to receive anything because the RTS signal isn't turned on. Setting RtsEnable to true will be required, that's what HyperTerminal does as well. Or just set the Handshake property correctly, Handshake.RequestToSend is the common requirement.
If you still have trouble then you can use SysInternals' PortMon to compare the serial port driver commands your program issues against the ones issued by HyperTerminal.
Hyperterminal likely appends a newline character to your input when you hit the Enter key to send information, which consists of a "line feed" and "carriage return".
Check the documentation for your hardware, but my guess is that the device you're attempting to send information to is looking for a carriage return, '\r', to signify the end of input. Like others in the comments are saying, append the appropriate character(s) to the end of your input.
Alternatively, you can use the SerialPort.WriteLine function to accomplish the same thing as appending a newline '\r\n' character to your input without explicitly modifying it.
if (serialPort.IsOpen)
serialPort.WriteLine("Command" + "\r\n");

IR transmitter for Air Conditioner using PC Serial Port

I have to control an air conditioner from pc serial port using IR LED, When I am reading the IR data from the serial port It gives nearly 160 characters, But actually my AC remote may send a address+command it may be 8 to 32 bit only. So I would like to know how to decode the IR data using only Serial port. Right now I am using C# code for reading the data. When I am using Terminal also it gives the same data.
The data is as follows:
ððpppððppððpðpðpðpppppppppppppðððpppppppððpððpðppppppppppppppppppppppppppppppppð
ðððøðxpxøøxxøøxøxðxðxppppppxpxpppðøøxxxxxxxøøxøøxøxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx
This is for ON button..
Please help me....
As a software developer I look at 'what is the intent'. So in this case I wonder if the intent is to control the air conditioner rather than write the code. :-)
If so, you may take the approach of use one of the many home automation products to capture the IR command and have your software trigger that 'saved' command.
"The fastest way to do something is to not do it at all" - Alister Cockburn.
If this is of any interest have a look at these:
http://www.redrat.co.uk/
http://www.usbuirt.com/
http://www.uk-automation.co.uk/products/SQ-IR-%28Infrared%29-Blaster.html
Good luck
Rob
Serial communications are always done at a particular speed, or baud rate. It sounds like you may not be reading the data at the correct baud rate. Do you know what the baud rate is supposed to be?
Looks like the baud rate is incorrect. 9600 is the most common for these kind of devices so make sure your serial port is set to that. Otherwise try all of them out or find some documentation telling you what it is.

Categories