TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Gary Soh
NA
5
1.9k
Visual C# problem, SerialPort DataReceive
Oct 4 2011 2:28 AM
Hello,
I am trying to translate my Visual Basic program to C#.
Right now i am have having problems translating this code
[CODE]Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
inchar = SerialPort1.ReadLine
IDstr = Microsoft.VisualBasic.Left(inchar, 2)
Datastr = Microsoft.VisualBasic.Right(inchar, 6)
result = Val("&h" & Datastr)
''Energy = (result * 38) / 1000
End Sub[/CODE]
I'd like to know how to make my IDstr read the most left 2 bits, and Datastr read the right most 6 bits.
For now i have this:
[CODE]private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
string inchar, IDstr, Datastr;
inchar = SerialPort1.ReadLine();
IDstr = Microsoft.VisualBasic.Left(inchar, 2); // need help translating this line
Datastr = Microsoft.VisualBasic.Right(inchar, 6); // need help translating this line
result = Val("&h" & Datastr);
/*''Energy = (result * 38) / 1000;*/
}[/CODE]
Thank you!
Reply
Answers (
5
)
Dropp Down List
Form loading take time