开发者

serial port added in one form not accessible from another class vb.net

开发者 https://www.devze.com 2023-02-27 02:42 出处:网络
I added a serial port com1 to 开发者_运维百科my vb.net form. I created a new class and wrote a method to open the com1 and created its object in the main form and called the method and its opening.

I added a serial port com1 to 开发者_运维百科my vb.net form. I created a new class and wrote a method to open the com1 and created its object in the main form and called the method and its opening.

THen i created another class wrote a method to write data to the com and same way created an object and called it but i am getting the error as port is closed. What am i doing wrong.

To open the port

public class openport public sub opencom mainform.com1.open end sub end class

//in the mian form

dim cc as openport

cc.opencom

'The above stuff works

But when i do same thing in another class for writing using

mainform.com1.write(data)

i am getting an error as port closed.


It looks like you are defining one comport, then opening a different one. Check that, if you still have issues post your complete code.

'Form1
public SP as SerialPort;
' Form1 Load Event
SP = New SerialPort("COM##", ...)
' Form1 Loads New Form
dim newForm as New Form2()
newForm.OldForm = Me
newForm.Show();

'Form2
public OldForm as Form1
'Form2 Minipulate COM port
OldForm.SP.Write(data) 
0

精彩评论

暂无评论...
验证码 换一张
取 消