Click here to Skip to main content
15,904,652 members
Home / Discussions / C#
   

C#

 
QuestionScientific calculator in C# Pin
Ronald246-Apr-06 13:48
Ronald246-Apr-06 13:48 
QuestionPixelation in Scaled GIF images Pin
Citizen_RobertK6-Apr-06 13:24
Citizen_RobertK6-Apr-06 13:24 
QuestionHide web service details? Pin
Mark Tutt6-Apr-06 12:56
Mark Tutt6-Apr-06 12:56 
AnswerRe: Hide web service details? Pin
Ferry Mulyono6-Apr-06 15:13
Ferry Mulyono6-Apr-06 15:13 
GeneralRe: Hide web service details? Pin
Mark Tutt6-Apr-06 15:41
Mark Tutt6-Apr-06 15:41 
GeneralRe: Hide web service details? Pin
Ferry Mulyono6-Apr-06 16:01
Ferry Mulyono6-Apr-06 16:01 
GeneralRe: Hide web service details? Pin
Mark Tutt6-Apr-06 16:35
Mark Tutt6-Apr-06 16:35 
QuestionPass SerialPort variable to another class. Pin
shultas6-Apr-06 12:03
shultas6-Apr-06 12:03 
Hey all. I'm new @ C# and I am trying to make a small application on my PC. Basically the functionality of this is to allow incoming TCP connections and pass them through to the COM port and vice versa. (So I can connect home and tell my TV to tune to a channel and start recording).

The parts function perfectly independently. I have a main class that spawns a new thread. That new thread opens up a SerialPort connection, and basically sits and waits for commands to be heard from the serialport (for my box to talk back to me and tell it that it did what I wanted it to do). When I do things on the TV, it talks to the COM port, and when I send it commands the TV receives them and does the command, so that part works fine.

Now the second part is my TCP/IP connection. I am using TcpServiceProvider to make this happen. It's listening on port 15555 for commands. When I run this (with MessageBox windows), when I telnet into it and send commands, it receives them, and when I send it commands it sees them just fine.

So, now my problem is tying the two of these classes together. Basically in my main class, I want to open the SerialPort connection and keep it open. I want the TCP server class to talk to the COM port through that variable that I created in the main class.

What I've done to try to accomplish this is in my TCP server class, I created a private variable like so:

private SerialPort _sp;

I created a method too:

public void SetSPVariable(SerialPort sp)
{
_sp = sp;
// for debug, I did this
_sp.Write("TEST");
}
public void TestComs()
{
_sp.Write("TESTING NUMBER TWO"); // this never works
}

It works fine when I call the SetSPVariable method. Now there are other methods within my TCP server class that need to talk to the serial port too (which is why I opted for the private variable within the class). Those other classes can not talk to it whatsoever. It just doesn't work and I can't figure out why. I've tried to pass by reference, but that didn't work either. So basically, in my main class I do something like this:

sp.Open(....);
sp.Write("This works fine");
TCPServerVariable.SetSPVariable(sp);
// at this point in time, you can see the TEST message coming out the COM port from within the
// TCPServer class
TCPServerVariable.TestComs();
// You never see the communication coming from there.

I know that the serial port is still being held open by the main class because when I send commands from another laptop via NULL MODEM cable they show up in the debug message.

I tried passing by reference, but that didn't seem to work. It appears that when the method is finished it somehow is messing up the local class _sp variable. I don't know why. Like I said I'm new to it, and it is probably something really silly.

I'd really appreciate any help on the matter. I've read through for three hours trying to figure this out, and I figure that it's about time to ask for help on the matter.

Thanks greatly

SHULTAS

AnswerRe: Pass SerialPort variable to another class. Pin
Judah Gabriel Himango6-Apr-06 12:32
sponsorJudah Gabriel Himango6-Apr-06 12:32 
AnswerRe: Pass SerialPort variable to another class. Pin
Stefan Troschuetz6-Apr-06 12:35
Stefan Troschuetz6-Apr-06 12:35 
GeneralRe: Pass SerialPort variable to another class. Pin
shultas6-Apr-06 12:49
shultas6-Apr-06 12:49 
GeneralRe: Pass SerialPort variable to another class. Pin
Stefan Troschuetz6-Apr-06 22:48
Stefan Troschuetz6-Apr-06 22:48 
QuestionMaybe not an interesting question, but... Pin
Stanciu Vlad6-Apr-06 11:55
Stanciu Vlad6-Apr-06 11:55 
AnswerRe: Maybe not an interesting question, but... Pin
Judah Gabriel Himango6-Apr-06 12:24
sponsorJudah Gabriel Himango6-Apr-06 12:24 
GeneralRe: Maybe not an interesting question, but... Pin
Stanciu Vlad6-Apr-06 22:33
Stanciu Vlad6-Apr-06 22:33 
GeneralRe: Maybe not an interesting question, but... Pin
Judah Gabriel Himango7-Apr-06 4:01
sponsorJudah Gabriel Himango7-Apr-06 4:01 
AnswerRe: Maybe not an interesting question, but... Pin
Graham Nimbley6-Apr-06 15:55
Graham Nimbley6-Apr-06 15:55 
QuestionHelp me..with this message..The server viewstate cache has timed out. Pin
jorgeils6-Apr-06 11:53
jorgeils6-Apr-06 11:53 
AnswerRe: Help me..with this message..The server viewstate cache has timed out. Pin
Judah Gabriel Himango6-Apr-06 12:23
sponsorJudah Gabriel Himango6-Apr-06 12:23 
QuestionPls Help me Pin
narendrakumarp6-Apr-06 10:30
narendrakumarp6-Apr-06 10:30 
AnswerRe: Pls Help me Pin
Judah Gabriel Himango6-Apr-06 12:22
sponsorJudah Gabriel Himango6-Apr-06 12:22 
QuestionList of running applications Pin
Sergey Gorchichko6-Apr-06 9:17
Sergey Gorchichko6-Apr-06 9:17 
AnswerRe: List of running applications Pin
Judah Gabriel Himango6-Apr-06 10:02
sponsorJudah Gabriel Himango6-Apr-06 10:02 
QuestionRandom in C# Pin
alee15.10.886-Apr-06 8:21
alee15.10.886-Apr-06 8:21 
GeneralRe: Random in C# Pin
Office Lineman6-Apr-06 8:35
Office Lineman6-Apr-06 8:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.