|
Well it's set to "true" for both ports.
Also, I just commented out the part in the code that opens the RS232 port, and instead used HyperTerminal to watch that one. Data sent out the USB port is caught by HyperTerminal... but not by the program itself. I can also send characters from HT and it shows up, as they are typed, in the program (which is to be expected, since data is being sent one byte at a time instead of the whole string).
I don't know if this will help or not, but I've got the whole program set to ignore any cross-threaded calls. Would this be a problem?
Take care,
Michael Fritzius
|
|
|
|
|
Hi,
matrix2681 wrote: ignore any cross-threaded calls. Would this be a problem?
It is in general a bad idea.
I don't expect it wil affect the serial port I guess, it will, if anything,
show up as a GUI that works half or not at all (immediately or after some time).
Do not do this. Fix it, you will have to fix it anyway, why run such risks now.
If all you need is visual feedback from some thread, use Console.WriteLine(),
that works all the time (towards Visual's output pane when running under Visual).
So your app receives, but is unable to transmit ? That is a first, most
people get the opposite.
I trust you have code for synchronous transmission, i.e. port.WriteLine() ?
IIRC the default settings are OK for simple transmission.
This is code from my very first SerialPort experiment:
SerialPort port;
...
port=new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
port.Encoding=Encoding.ASCII;
port.NewLine="\r\n";
port.Open();
...
port.WriteLine(someString);
Hope this helps.
|
|
|
|
|
matrix2681 wrote: Well it's set to "true" for both ports
That cant be true, if one port belongs to your app, trying to transmit;
and the other port is handled by HyperTerminal.
Either your app or HT must be failing to open the port (who ever comes last).
You are putting things in try-catch and properly showing all exceptions, are you ?
|
|
|
|
|
Here's what I have for initializing the ports:
serialPort1.ReadTimeout = 1000;<br />
serialPort1.BaudRate = 115200;<br />
serialPort1.StopBits = StopBits.One;<br />
serialPort1.Parity = Parity.None;<br />
serialPort1.DataBits = 8;<br />
serialPort1.RtsEnable = true;<br />
serialPort1.PortName = "COM1";<br />
serialPort1.Encoding = Encoding.ASCII;<br />
<br />
serialPort2.ReadTimeout = 1000;<br />
serialPort2.BaudRate = 115200;<br />
serialPort2.StopBits = StopBits.One;<br />
serialPort2.Parity = Parity.None;<br />
serialPort2.DataBits = 8;<br />
serialPort2.RtsEnable = true;<br />
serialPort2.PortName = "COM5";<br />
serialPort2.Encoding = Encoding.ASCII;<br />
I added a couple of buttons that can turn on/off the ports on the fly, so I can test with HyperTerminal if needed. But both port have RTS line enabled. The ports aren't opened immediately after the program starts, but the settings are set. Just press a button and go for it. port 1 is the RS232 and port 5 is the USB.
Here's how I handle sending/receiving messages:
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)<br />
{<br />
txtfromusb.Text += (serialPort1.ReadExisting());<br />
}<br />
<br />
private void serialPort2_DataReceived(object sender, SerialDataReceivedEventArgs e)<br />
{<br />
txtfromrs232.Text += (serialPort2.ReadExisting());<br />
}<br />
<br />
private void sendfromrs232btn_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
sendtextfromrs232.Text += "\r";<br />
serialPort1.WriteLine(sendtextfromrs232.Text);<br />
sendtextfromrs232.Text = "";<br />
baudRatelLabel.Text = "Ready";<br />
}<br />
catch (System.Exception ex)<br />
{<br />
baudRatelLabel.Text = ex.Message;<br />
}<br />
}<br />
<br />
private void sendtextfromrs232_Click(object sender, EventArgs e)<br />
{<br />
sendtextfromrs232.Clear();<br />
}<br />
<br />
private void sendtxtfromusb_Click(object sender, EventArgs e)<br />
{<br />
sendtxtfromusb.Clear();<br />
}<br />
<br />
private void sendfromusbbtn_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
sendtxtfromusb.Text += "\r";<br />
serialPort2.WriteLine(sendtxtfromusb.Text);<br />
sendtxtfromusb.Text = "";<br />
baudRatelLabel.Text = "Ready";<br />
}<br />
catch (System.Exception ex)<br />
{<br />
baudRatelLabel.Text = ex.Message;<br />
}<br />
<br />
}<br />
Oh I am so stuck Can I send you the entire project? I know you said you were working on something similar, so if you have the hardware ready, maybe you can get further than I have.
Take care,
Michael Fritzius
|
|
|
|
|
Hi,
I am not going to adopt your project right now.
I suggest you show more of the code: the instantiation of the port(s),
and the read and write code.
You have not yet told whether they are synchronous/asynchronous, and I am
getting the impression you are mixing characters and bytes, which are not
interchangeable (a char is 16-bit Unicode, a byte is 8-bit).
And you have not given clear symptoms:
HT (as a receiver) shows nothing at all ? some good chars + some strange chars ?
only strange chars ?
|
|
|
|
|
The code I put up before is almost the whole thing, short of a few housekeeping snippets like clearing the textbox when the user clicks on it. I think this message you sent was sent before you saw the code though.
When both ports are examined by HT (not using my program at all), the ports can talk to each other just fine, both ways. So the hardware is solid.
When my program is running and sending data out one port, with HT receiving on the other, HT can receive all data, regardless of if it's looking at the RS232 or the USB.
The problem shows up when I try to use only my program. Data can come in the USB port, but data sent out the USB port either gets garbled, or is misunderstood by the converter or something else.
(also I tried reversing the cable, and it still works in the same way listed above, so it is in fact a null modem cable, like what I need )
I know this seems really weird, and it seems like it SHOULD work... but for whatever reason, a transfer from USB to RS232 just ain't happening in my program.
I just thought of something... do you think that including the driver DLL that came with the converter as a reference would help? I mean it's obvious that HT has the ability to get and understand whatever is coming in the USB port. Could it be that HT is making use of something that I have to tell my program to make use of the same DLL or something?
|
|
|
|
|
Give this a try:
replace both lines containing port.WriteLine(...) by port.WriteLine("abcdefghijk");
and test again.
|
|
|
|
|
|
That's too bad.
Writing to a serial port is the simplest part of it all. It takes no more than 10
to 15 lines of code to come up with an entire Console app that does exactly that.
And that is the only thing I can recommend under the current circumstances.
Good luck.
|
|
|
|
|
Ok let's try a different approach then.
I'm noticing the common problem being when data comes out the USB--either from the program or HT--and goes to the RS232 that's associated with the program. The common thing is the RS232 when the program is running.
Is there any reason why the RS232 wouldn't understand input?
Thanks for your time so far, there are a lot of things I wouldn't have guessed at had it not been for your input.
Take care,
Michael Fritzius
|
|
|
|
|
correction
Seems I somehow missed reading part of your last message.
my current impression is you confused yourself having two ports in your app.
matrix2681 wrote: //write line to USB port
sendtextfromrs232.Text += "\r";
serialPort1.WriteLine(sendtextfromrs232.Text);
//clear the text box
sendtextfromrs232.Text = "";
The above seems inconsistent, are you refering the right TextBox (or whatever
sendtextfromrs232/USB may be) ?
|
|
|
|
|
This is just the box that holds the text to be sent out the RS232 port. All it does is send it using the WriteLine() command and clear the box. The other method for this, the one that uses serialPort2 is the one associated with the USB port. It works the same way.
|
|
|
|
|
it works ?
if it works, we are done.
if it does not work, we must simplify till it works.
I am getting confused and I think so are you, seems to me you are sending the
content of the wrong box. So try a constant to end all doubts.
|
|
|
|
|
Nope, setting the writeline command to send out a constant didn't work.
I drew up a table to figure out what combinations really do and don't work. It shows that regardless of how I send data out the USB port--if it's the program or if it's HT--the RS232 in the program doesn't receive the data.
This sure is strange.
|
|
|
|
|
So are you saying now that your program is able to send after all ?
If so I recommend a long shower.
You told us earlier that receiving was no problem, transmission was the problem.
|
|
|
|
|
That's because originally I thought there was something wrong with transmitting out the USB port, since I was just using the program. After some testing with HT, I know that's not the case. Now I'm seeing the common thread being the program's RS232 port.
|
|
|
|
|
Hi all,
Ok here is the scenario. I wrote an application which reads information from a access database
and then the user has the option to export it to an MS word Document. This work 100% on some machines but troughs a Runtime error on other.
Here is a code snippet.
ApplicationClass wordApp = new Word.ApplicationClass();
//Error when creating event.
wordApp.DocumentBeforeClose += new Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(wordApp_DocumentBeforeClose);
I almost don't see this being a code/logical error, may it be the version of Office
that differs on the PC's?
Thanx in advance
|
|
|
|
|
I have seen some issues, where if office is installed before the .net framework. The .net hooks into office don't get installed. So if you go into add remove programs and fix the install of office you should see a .net option that wasn't there before, if you istall the .net hooks then it should work for you.
Hope that helps.
Ben
|
|
|
|
|
Hi,
Thanx for the reply, I'm not too sure with the whole hooks concept.
But correct me if I am wrong, If I reinstall Office/Repair the installation
I don't have to do anything else???
If so I'll give it a shot and let u know!
Oh ja, one thing I forgot to mention is that only the events raises an error, I put them in a try/catch
block and the failed of cause but the word document still opened... Make any sense?
-- modified at 10:58 Thursday 26th July, 2007
|
|
|
|
|
When you reinstall / fix office there is a new option that talks about add .net components. You should see that if office was installed before the .net framework.
Ben
|
|
|
|
|
Hello,
In my application, I have to get a microsecond resolution for a timer.
Is it possible to do (on WinXP or Vista) ?
There should be high precision timers in kernel mode, but what is it and how could I get to them from .Net code?
All help will be appreciated.
Roman
-- Everything is possible, even the impossible! ^_^
|
|
|
|
|
Luc's article[^] is probably the definitive article on the subject.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Already read and tested, with this I can only get 1 millisecond resolution (Multimedia Timer), but I need 1 microsecond...
-- Everything is possible, even the impossible! ^_^
|
|
|
|
|
If you need to control timing that tightly, then you need a real time OS. There are several flavors of *nix that are, but windows is not.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
Yeah, but it should work in windows. I'm sure there's something like nanosleep in win32 kernel mode.
-- Everything is possible, even the impossible! ^_^
|
|
|
|