I am using visual studio to create an application that would allow the user to select an item out of a listbox and hit "Run". Once the user hits run I want the application to write the byte value associated to the selected string item via a serial port interface. The listbox is populated with an enumeration of bytes such as:
public enum Commands : byte
{
cmd1 = 0xF1,
cmd2 = 0xA4,
cmd3 = 0x04
}my ListBox is populated as follows:
private void Form_Load(object sender, EventArgs e)
{
foreach(string myType in Enum.GetNames(typeof (Commands)))
{
listbox.Commands.Add(myType);
}
}So far I've hit a wall trying to find a way to write 0xF1 when the user selects "Cmd1" from the listbox. I've tried doing things like casting the selected item to a byte (see below) but nothing has worked so far.
port.Write((byte)listbox.SelectedItem);Any help would be greatly appreciated!