Scoreboard data transfer Serial Port c#












-1














There's some outdated software that's used to control the scoreboard at my local athletics track and I've been tasked with creating a new advanced one. However, I cannot seem to get the scoreboard to do what I ask it to do.



I've installed the original software to the my laptop and it works fine, however, when I run my test software that sends data to the board through the serial port, it isn't doing what I want.



I have the "Scoreboard Data Protocol" supplied by the manufacturer and I've been following this. I will supply the code to my test program that I've been using to see if I can get it to work and I will also supply the Data Protocol.



In the text box, I type 010D0201SPAIN and 003C630 and send it to the board and this doesn't work.



public partial class Form1 : Form
{

private SerialPort m_port;

public Form1()
{
InitializeComponent();
m_list.Items.AddRange(SerialPort.GetPortNames()); // Adds ports to combobox

m_port = new SerialPort();
m_port.BaudRate = 9600;
m_port.DataBits = 8;
m_port.Parity = Parity.Even;
m_port.StopBits = StopBits.One;
//m_port.Handshake = Handshake.None;
m_port.Encoding = new ASCIIEncoding();

m_port.RtsEnable = true;
m_port.DtrEnable = true;

m_port.ReceivedBytesThreshold = 1;
m_port.DataReceived += DataReceivedEvent;
}

private void button1_Click(object sender, EventArgs e)
{
m_port.Close();
m_port.PortName = (string)m_list.SelectedItem;

try
{
m_port.Open();
m_sendbutton.Enabled = true;
button2.Enabled = true;
}catch(UnauthorizedAccessException ex)
{
MessageBox.Show(ex.Message);
}
}

private void m_sendbutton_Click(object sender, EventArgs e)
{
m_port.Write(m_textbox.Text);
}
private void DataReceivedEvent(object sender, SerialDataReceivedEventArgs args)
{
Invoke(new EventHandler(DoUpdate));
}

private void DoUpdate(object s, EventArgs e)
{
label1.Text += m_port.ReadLine();
}

private void button2_Click(object sender, EventArgs e)
{
byte r_bytes = Encoding.ASCII.GetBytes(m_textbox.Text);
m_port.Write(r_bytes, 0, r_bytes.Length);
}
}
}


Scoreboard Data Protocol



Code: https://hastebin.com/epirobuduv.cs










share|improve this question
























  • " it isn't doing what I want." - can you explain what happens, and what you would like it to do instead?
    – Robin Bennett
    Nov 20 '18 at 11:20










  • Okay so at the moment, it does nothing when I send info from the program above, however when I send messages from the old software from 2004, it works fine. So there is something wrong with my code. I send 010D0201SPAIN and 003C630 through my program and that should display the word SPAIN (as the data protocol says) but it doesn't happen.
    – Jack B
    Nov 20 '18 at 11:24










  • You made no attempt whatsoever to implement the protocol. Impossible to guess what the problem might be, you need to ask a specific question about it.
    – Hans Passant
    Nov 20 '18 at 11:34










  • @HansPassant In the text box, I enter 010D0201SPAIN and 003C630 and the scoreboard doesn't do what it says in the protocol
    – Jack B
    Nov 20 '18 at 11:40










  • That was obvious, but that is not what the protocol says you need to do. Read up about the control codes that indicate the start and end of a message. Use Read and Write instead of Read/WriteLine().
    – Hans Passant
    Nov 20 '18 at 11:49
















-1














There's some outdated software that's used to control the scoreboard at my local athletics track and I've been tasked with creating a new advanced one. However, I cannot seem to get the scoreboard to do what I ask it to do.



I've installed the original software to the my laptop and it works fine, however, when I run my test software that sends data to the board through the serial port, it isn't doing what I want.



I have the "Scoreboard Data Protocol" supplied by the manufacturer and I've been following this. I will supply the code to my test program that I've been using to see if I can get it to work and I will also supply the Data Protocol.



In the text box, I type 010D0201SPAIN and 003C630 and send it to the board and this doesn't work.



public partial class Form1 : Form
{

private SerialPort m_port;

public Form1()
{
InitializeComponent();
m_list.Items.AddRange(SerialPort.GetPortNames()); // Adds ports to combobox

m_port = new SerialPort();
m_port.BaudRate = 9600;
m_port.DataBits = 8;
m_port.Parity = Parity.Even;
m_port.StopBits = StopBits.One;
//m_port.Handshake = Handshake.None;
m_port.Encoding = new ASCIIEncoding();

m_port.RtsEnable = true;
m_port.DtrEnable = true;

m_port.ReceivedBytesThreshold = 1;
m_port.DataReceived += DataReceivedEvent;
}

private void button1_Click(object sender, EventArgs e)
{
m_port.Close();
m_port.PortName = (string)m_list.SelectedItem;

try
{
m_port.Open();
m_sendbutton.Enabled = true;
button2.Enabled = true;
}catch(UnauthorizedAccessException ex)
{
MessageBox.Show(ex.Message);
}
}

private void m_sendbutton_Click(object sender, EventArgs e)
{
m_port.Write(m_textbox.Text);
}
private void DataReceivedEvent(object sender, SerialDataReceivedEventArgs args)
{
Invoke(new EventHandler(DoUpdate));
}

private void DoUpdate(object s, EventArgs e)
{
label1.Text += m_port.ReadLine();
}

private void button2_Click(object sender, EventArgs e)
{
byte r_bytes = Encoding.ASCII.GetBytes(m_textbox.Text);
m_port.Write(r_bytes, 0, r_bytes.Length);
}
}
}


Scoreboard Data Protocol



Code: https://hastebin.com/epirobuduv.cs










share|improve this question
























  • " it isn't doing what I want." - can you explain what happens, and what you would like it to do instead?
    – Robin Bennett
    Nov 20 '18 at 11:20










  • Okay so at the moment, it does nothing when I send info from the program above, however when I send messages from the old software from 2004, it works fine. So there is something wrong with my code. I send 010D0201SPAIN and 003C630 through my program and that should display the word SPAIN (as the data protocol says) but it doesn't happen.
    – Jack B
    Nov 20 '18 at 11:24










  • You made no attempt whatsoever to implement the protocol. Impossible to guess what the problem might be, you need to ask a specific question about it.
    – Hans Passant
    Nov 20 '18 at 11:34










  • @HansPassant In the text box, I enter 010D0201SPAIN and 003C630 and the scoreboard doesn't do what it says in the protocol
    – Jack B
    Nov 20 '18 at 11:40










  • That was obvious, but that is not what the protocol says you need to do. Read up about the control codes that indicate the start and end of a message. Use Read and Write instead of Read/WriteLine().
    – Hans Passant
    Nov 20 '18 at 11:49














-1












-1








-1







There's some outdated software that's used to control the scoreboard at my local athletics track and I've been tasked with creating a new advanced one. However, I cannot seem to get the scoreboard to do what I ask it to do.



I've installed the original software to the my laptop and it works fine, however, when I run my test software that sends data to the board through the serial port, it isn't doing what I want.



I have the "Scoreboard Data Protocol" supplied by the manufacturer and I've been following this. I will supply the code to my test program that I've been using to see if I can get it to work and I will also supply the Data Protocol.



In the text box, I type 010D0201SPAIN and 003C630 and send it to the board and this doesn't work.



public partial class Form1 : Form
{

private SerialPort m_port;

public Form1()
{
InitializeComponent();
m_list.Items.AddRange(SerialPort.GetPortNames()); // Adds ports to combobox

m_port = new SerialPort();
m_port.BaudRate = 9600;
m_port.DataBits = 8;
m_port.Parity = Parity.Even;
m_port.StopBits = StopBits.One;
//m_port.Handshake = Handshake.None;
m_port.Encoding = new ASCIIEncoding();

m_port.RtsEnable = true;
m_port.DtrEnable = true;

m_port.ReceivedBytesThreshold = 1;
m_port.DataReceived += DataReceivedEvent;
}

private void button1_Click(object sender, EventArgs e)
{
m_port.Close();
m_port.PortName = (string)m_list.SelectedItem;

try
{
m_port.Open();
m_sendbutton.Enabled = true;
button2.Enabled = true;
}catch(UnauthorizedAccessException ex)
{
MessageBox.Show(ex.Message);
}
}

private void m_sendbutton_Click(object sender, EventArgs e)
{
m_port.Write(m_textbox.Text);
}
private void DataReceivedEvent(object sender, SerialDataReceivedEventArgs args)
{
Invoke(new EventHandler(DoUpdate));
}

private void DoUpdate(object s, EventArgs e)
{
label1.Text += m_port.ReadLine();
}

private void button2_Click(object sender, EventArgs e)
{
byte r_bytes = Encoding.ASCII.GetBytes(m_textbox.Text);
m_port.Write(r_bytes, 0, r_bytes.Length);
}
}
}


Scoreboard Data Protocol



Code: https://hastebin.com/epirobuduv.cs










share|improve this question















There's some outdated software that's used to control the scoreboard at my local athletics track and I've been tasked with creating a new advanced one. However, I cannot seem to get the scoreboard to do what I ask it to do.



I've installed the original software to the my laptop and it works fine, however, when I run my test software that sends data to the board through the serial port, it isn't doing what I want.



I have the "Scoreboard Data Protocol" supplied by the manufacturer and I've been following this. I will supply the code to my test program that I've been using to see if I can get it to work and I will also supply the Data Protocol.



In the text box, I type 010D0201SPAIN and 003C630 and send it to the board and this doesn't work.



public partial class Form1 : Form
{

private SerialPort m_port;

public Form1()
{
InitializeComponent();
m_list.Items.AddRange(SerialPort.GetPortNames()); // Adds ports to combobox

m_port = new SerialPort();
m_port.BaudRate = 9600;
m_port.DataBits = 8;
m_port.Parity = Parity.Even;
m_port.StopBits = StopBits.One;
//m_port.Handshake = Handshake.None;
m_port.Encoding = new ASCIIEncoding();

m_port.RtsEnable = true;
m_port.DtrEnable = true;

m_port.ReceivedBytesThreshold = 1;
m_port.DataReceived += DataReceivedEvent;
}

private void button1_Click(object sender, EventArgs e)
{
m_port.Close();
m_port.PortName = (string)m_list.SelectedItem;

try
{
m_port.Open();
m_sendbutton.Enabled = true;
button2.Enabled = true;
}catch(UnauthorizedAccessException ex)
{
MessageBox.Show(ex.Message);
}
}

private void m_sendbutton_Click(object sender, EventArgs e)
{
m_port.Write(m_textbox.Text);
}
private void DataReceivedEvent(object sender, SerialDataReceivedEventArgs args)
{
Invoke(new EventHandler(DoUpdate));
}

private void DoUpdate(object s, EventArgs e)
{
label1.Text += m_port.ReadLine();
}

private void button2_Click(object sender, EventArgs e)
{
byte r_bytes = Encoding.ASCII.GetBytes(m_textbox.Text);
m_port.Write(r_bytes, 0, r_bytes.Length);
}
}
}


Scoreboard Data Protocol



Code: https://hastebin.com/epirobuduv.cs







c#






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 11:41

























asked Nov 20 '18 at 11:10









Jack B

51




51












  • " it isn't doing what I want." - can you explain what happens, and what you would like it to do instead?
    – Robin Bennett
    Nov 20 '18 at 11:20










  • Okay so at the moment, it does nothing when I send info from the program above, however when I send messages from the old software from 2004, it works fine. So there is something wrong with my code. I send 010D0201SPAIN and 003C630 through my program and that should display the word SPAIN (as the data protocol says) but it doesn't happen.
    – Jack B
    Nov 20 '18 at 11:24










  • You made no attempt whatsoever to implement the protocol. Impossible to guess what the problem might be, you need to ask a specific question about it.
    – Hans Passant
    Nov 20 '18 at 11:34










  • @HansPassant In the text box, I enter 010D0201SPAIN and 003C630 and the scoreboard doesn't do what it says in the protocol
    – Jack B
    Nov 20 '18 at 11:40










  • That was obvious, but that is not what the protocol says you need to do. Read up about the control codes that indicate the start and end of a message. Use Read and Write instead of Read/WriteLine().
    – Hans Passant
    Nov 20 '18 at 11:49


















  • " it isn't doing what I want." - can you explain what happens, and what you would like it to do instead?
    – Robin Bennett
    Nov 20 '18 at 11:20










  • Okay so at the moment, it does nothing when I send info from the program above, however when I send messages from the old software from 2004, it works fine. So there is something wrong with my code. I send 010D0201SPAIN and 003C630 through my program and that should display the word SPAIN (as the data protocol says) but it doesn't happen.
    – Jack B
    Nov 20 '18 at 11:24










  • You made no attempt whatsoever to implement the protocol. Impossible to guess what the problem might be, you need to ask a specific question about it.
    – Hans Passant
    Nov 20 '18 at 11:34










  • @HansPassant In the text box, I enter 010D0201SPAIN and 003C630 and the scoreboard doesn't do what it says in the protocol
    – Jack B
    Nov 20 '18 at 11:40










  • That was obvious, but that is not what the protocol says you need to do. Read up about the control codes that indicate the start and end of a message. Use Read and Write instead of Read/WriteLine().
    – Hans Passant
    Nov 20 '18 at 11:49
















" it isn't doing what I want." - can you explain what happens, and what you would like it to do instead?
– Robin Bennett
Nov 20 '18 at 11:20




" it isn't doing what I want." - can you explain what happens, and what you would like it to do instead?
– Robin Bennett
Nov 20 '18 at 11:20












Okay so at the moment, it does nothing when I send info from the program above, however when I send messages from the old software from 2004, it works fine. So there is something wrong with my code. I send 010D0201SPAIN and 003C630 through my program and that should display the word SPAIN (as the data protocol says) but it doesn't happen.
– Jack B
Nov 20 '18 at 11:24




Okay so at the moment, it does nothing when I send info from the program above, however when I send messages from the old software from 2004, it works fine. So there is something wrong with my code. I send 010D0201SPAIN and 003C630 through my program and that should display the word SPAIN (as the data protocol says) but it doesn't happen.
– Jack B
Nov 20 '18 at 11:24












You made no attempt whatsoever to implement the protocol. Impossible to guess what the problem might be, you need to ask a specific question about it.
– Hans Passant
Nov 20 '18 at 11:34




You made no attempt whatsoever to implement the protocol. Impossible to guess what the problem might be, you need to ask a specific question about it.
– Hans Passant
Nov 20 '18 at 11:34












@HansPassant In the text box, I enter 010D0201SPAIN and 003C630 and the scoreboard doesn't do what it says in the protocol
– Jack B
Nov 20 '18 at 11:40




@HansPassant In the text box, I enter 010D0201SPAIN and 003C630 and the scoreboard doesn't do what it says in the protocol
– Jack B
Nov 20 '18 at 11:40












That was obvious, but that is not what the protocol says you need to do. Read up about the control codes that indicate the start and end of a message. Use Read and Write instead of Read/WriteLine().
– Hans Passant
Nov 20 '18 at 11:49




That was obvious, but that is not what the protocol says you need to do. Read up about the control codes that indicate the start and end of a message. Use Read and Write instead of Read/WriteLine().
– Hans Passant
Nov 20 '18 at 11:49












1 Answer
1






active

oldest

votes


















0














Here's how to add STX and ETX around your message, in a byte array.



   private void button2_Click(object sender, EventArgs e)
{
var msg = Encoding.ASCII.GetBytes(m_textbox.Text).ToList();
msg.Insert(0, 0x02); // STX at the start
msg.Add(0x03); // ETX at the end
m_port.Write(msg.ToArray(), 0, msg.Count);
}





share|improve this answer























  • @Jack B - Would 'msg.Count' work? That would be neater.
    – Robin Bennett
    Nov 20 '18 at 12:19










  • Yep, that works fine! Thankyou!
    – Jack B
    Nov 20 '18 at 12:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391705%2fscoreboard-data-transfer-serial-port-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Here's how to add STX and ETX around your message, in a byte array.



   private void button2_Click(object sender, EventArgs e)
{
var msg = Encoding.ASCII.GetBytes(m_textbox.Text).ToList();
msg.Insert(0, 0x02); // STX at the start
msg.Add(0x03); // ETX at the end
m_port.Write(msg.ToArray(), 0, msg.Count);
}





share|improve this answer























  • @Jack B - Would 'msg.Count' work? That would be neater.
    – Robin Bennett
    Nov 20 '18 at 12:19










  • Yep, that works fine! Thankyou!
    – Jack B
    Nov 20 '18 at 12:23
















0














Here's how to add STX and ETX around your message, in a byte array.



   private void button2_Click(object sender, EventArgs e)
{
var msg = Encoding.ASCII.GetBytes(m_textbox.Text).ToList();
msg.Insert(0, 0x02); // STX at the start
msg.Add(0x03); // ETX at the end
m_port.Write(msg.ToArray(), 0, msg.Count);
}





share|improve this answer























  • @Jack B - Would 'msg.Count' work? That would be neater.
    – Robin Bennett
    Nov 20 '18 at 12:19










  • Yep, that works fine! Thankyou!
    – Jack B
    Nov 20 '18 at 12:23














0












0








0






Here's how to add STX and ETX around your message, in a byte array.



   private void button2_Click(object sender, EventArgs e)
{
var msg = Encoding.ASCII.GetBytes(m_textbox.Text).ToList();
msg.Insert(0, 0x02); // STX at the start
msg.Add(0x03); // ETX at the end
m_port.Write(msg.ToArray(), 0, msg.Count);
}





share|improve this answer














Here's how to add STX and ETX around your message, in a byte array.



   private void button2_Click(object sender, EventArgs e)
{
var msg = Encoding.ASCII.GetBytes(m_textbox.Text).ToList();
msg.Insert(0, 0x02); // STX at the start
msg.Add(0x03); // ETX at the end
m_port.Write(msg.ToArray(), 0, msg.Count);
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 12:30









Jack B

51




51










answered Nov 20 '18 at 12:03









Robin Bennett

1,432112




1,432112












  • @Jack B - Would 'msg.Count' work? That would be neater.
    – Robin Bennett
    Nov 20 '18 at 12:19










  • Yep, that works fine! Thankyou!
    – Jack B
    Nov 20 '18 at 12:23


















  • @Jack B - Would 'msg.Count' work? That would be neater.
    – Robin Bennett
    Nov 20 '18 at 12:19










  • Yep, that works fine! Thankyou!
    – Jack B
    Nov 20 '18 at 12:23
















@Jack B - Would 'msg.Count' work? That would be neater.
– Robin Bennett
Nov 20 '18 at 12:19




@Jack B - Would 'msg.Count' work? That would be neater.
– Robin Bennett
Nov 20 '18 at 12:19












Yep, that works fine! Thankyou!
– Jack B
Nov 20 '18 at 12:23




Yep, that works fine! Thankyou!
– Jack B
Nov 20 '18 at 12:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391705%2fscoreboard-data-transfer-serial-port-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy