|
TJS4u wrote: i treid the code below but nothing happens....
That's incorrect, as something did happen. Either you didn't see it happen, or you didn't understand what happens.
The serial port doesn't "remember" that you sent an "A", since there is no memory attached to the serial port. Did you get an exception, or did the serial-port just 'eat' the information you sent?
Same problem with reading from the serial port. If there isn't anything attached and sending messages, then there won't be anything to read from the port.
Your best option would be going out to buy a "null-modem cable", or something that can echo the signals from the serial port.
I wish you lots of luck, as you are going to need it
|
|
|
|
|
hello Eddy Vluggen
i am new to C#.. so asking such questions...
the code is executing and when it enters the line
string line=...................
the system hangs
wht to do next
How can i be sure that the port is enabled and data has been send to the port...
OR if i connect a device will that respond to the code i have written
i await u r suggestions
Thanks
|
|
|
|
|
TJS4u wrote: the system hangs
No, it's not hanging, but waiting. Waiting for someone to send a carriage-return + linefeed to the serial port. In other words, the system is reading from the serial port, and will continue reading, until someone sends an "enter" to the serial port.
TJS4u wrote: How can i be sure that the port is enabled and data has been send to the port...
Make yourself a cable that echo's everything.
TJS4u wrote: if i connect a device will that respond to the code i have written
The device doesn't know about your code. Your code will have to speak to the device in a way that the device itself understands. Various devices use the serial port in different ways. Your micrologger will have some examples on this.
|
|
|
|
|
hello Eddy Vluggen
Thanks for u r reply
still some things makes confusing///
i have written
string line = serialPort1.ReadLine();
At this point will the variable line stores the value from the port???
if a device is connected and it has some thing to return
Thanks
|
|
|
|
|
TJS4u wrote:
string line = serialPort1.ReadLine();
At this point will the variable line stores the value from the port???
At that point the computer will *wait*, until a device sends an "enter". It will keep stuffing all data into the "line" variable, until it receives the enter-character.
Does your logger send a return-character when it is done sending data?
|
|
|
|
|
hello Eddy
the microcontoller will get the code which is downloaded to it thru the port and it will execute
after execution the result is send to the application thru the serial port from the microcontroller
Thanks
|
|
|
|
|
TJS4u wrote: the microcontoller will get the code which is downloaded to it thru the port and it will execute
You're sending "code" to the controller? I'm afraid I don't understand what you're saying here, can you give an example of the codes that you wanna send?
TJS4u wrote: after execution the result is send to the application thru the serial port from the microcontroller
..and the ReadLine() method will "hang" until the microcontroller sends this "enter"-character. I bet that the logger doesn't send it
It works if you remove that line, doesn't it?
|
|
|
|
|
Hi,
It is my impression this project is way beyond your current reach. Nevertheless here are some facts:
1.
transmit and receive channels are (almost) completely independent: there is a wire in each direction, there is separate electronics, separate data buffers, and different methods to call.
The only link exists inside the serial driver when software dataflow is used (XON/XOFF).
2.
whatever gets sent through a serial port is gone in a couple of micro- or milliseconds, you can't read it back; you can (if things go well) find the data at the target hardware after that delay.
Some suggestions:
1.
if all is new to you (C#, serial ports, microcontroller) you have zero probability to get it working by just setting it all up and hope for the best. You MUST go step by step, debug each step completely before taking the next step.
2.
The first step should be one of these (in increasing level of difficulty):
2a. use two PC's (I'll call them master and target) connect them through a serial cable WITH A NULL MODEM (which switches transmit and receive lines); run a terminal emulator (HyperTerminal, whatever) on the target PC, so you make it emulate your microcontroller by reading the emulator display and typing keys when appropriate. And run your own code on the master PC. Now you can first debug transmission: your program writing, the emulator showing what comes in; then you can tackle the receive side (with buffers, events, etc).
2b. you could try the same on a single PC (using two serial ports, connected with again a NULL MODEM); it is much less comfortable though.
2c. you don't even need real serial ports and a null modem cable, you can use a VIRTUAL NULL MODEM
(Google for com0com).
3. If all this works, you could try to use the microcontroller. If that one needs a program download, you'd better won't need its serial port for that, since it has not been debugged yet,
so it will not work initially.
Good luck.
|
|
|
|
|
how i open my form as open in .net by mouseover on properties,solution explorer etc.
i want to open form as when u add new form in .net in solution explorer i want create my strip and on a tab name say print on mouse over a form slide and show and on mouse out it slide again to left or right. i want to do in my mdi form
thanks.
send solution on sharma_diw@hotmail.com
modified on Tuesday, December 9, 2008 6:56 AM
|
|
|
|
|
You open a form by calling either .Show() or .ShowDialog() on the form object.
If you want to do it in the mouse over, you must add an event handler to the mouse over event, and show the new form from there.
Simon
|
|
|
|
|
Add a event on Mouseover that should open the form
Cheers!!
Brij
|
|
|
|
|
hello all
I want to write some data to a serial port and Read from the Port the data and display in a textbox ...
how can i do this
|
|
|
|
|
|
hello Simon Stevens
i treid the code below but nothing happens....
serialPort1.PortName = "COM1";
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.Open();
serialPort1.Write("A");
serialPort1.Close();
serialPort1.Open();
textBox1.Text = serialPort1.ReadLine();
|
|
|
|
|
TJS4u wrote: i treid the code below but nothing happens....
That is because you are not doing anything! What are you expecting? Do you know how to use a serial port?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
hello leppie
my requirement is to connect a microcontrolelr to the serial port .
i tried this to see if data is in the buffer ... then it can't be read back
Thanks
|
|
|
|
|
What are you expecting to happen? You can't just write "A" to a serial port and then expect to read it back.
You need to have some hardware connected to the serial port that either responds to data, or transmits data in.
Simon
|
|
|
|
|
You can use SerialPort class in System.IO.Ports namespace for communicating with serial port. It provides various methods/event to read and write data.
|
|
|
|
|
hello
i treid the code below but nothing happens....
serialPort1.PortName = "COM1";
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.Open();
serialPort1.Write("A");
serialPort1.Close();
serialPort1.Open();
textBox1.Text = serialPort1.ReadLine();
|
|
|
|
|
Hi,
I think you are going in wrong direction. Serial port are buffered port and it has got two seperate data line, which are TX (Transmit) and RX(Receive). Now if you send any data to your serial port it's there in TX buffer. So which ever device connected to this serial port suppose to get that.
So, you want to see whether this code working for you or not. So do one thing. Get one RS232 connector and short both RX pin and TX pin. Now try the same code, it should work. This is called loopback mechanism in hardware style.
If you don't have this connector then there are few utility software which create virtual serial port and same utility can create loopback mechanism also. This is loopback in software style.
I am sure either of two approach should solve your problem. Please let me know if you still face issues.
Himadri
|
|
|
|
|
Seriously, aren't there enough articles about this topic here on CP?
That's what the search function is for.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi
I would like to draw an image that contains lines , text and rectangles.
In order to draw it I need to use the graphics object.
Also I would like window\control will handle scroll bar, drawing the image automatically in case the image move with the mouse for example, so I was thinking to use image object in order to store my image
How can I export the image I created manually from graphic object (after I create all the items I want such as line, rectangle, etc on panel for example) to image object?
Thanks
Ronen
|
|
|
|
|
You don't need to - just create a new Bitmap, the create a new graphics object, and draw to that
e.g. something like
Bitmap bmp = new Bitmap( 640, 480 );
using( Graphics G = Graphics.FromImage(bmp) )
{
G.FillRectangle(...);
}
|
|
|
|
|
OK Thank u all,
Itry to draw to bitmap and it work great
How can I display it in the form
Should I create picturebox control and load the bitmap to it?
I would like the form to create scroll bar automaticly if need (in case the form is smaller then the bitmap image)
Ronen
|
|
|
|
|
Hi,
you can create a Bitmap, obtain the corresponding Graphics (through Graphics.FromImage), paint
to your hearts content, then use Bitmap.Save
BTW: there are several articles about Paint-like apps here on CP.
|
|
|
|