Witam,
Mam pytanie czy za pomocą Visual Web Developer możiwe jest sterowanie portem szeregowym RS232? tzn. chce zrobic buttona w ASP.Net WEB Aplication za pomocą którego bedzie wysyłny syg do sterownika.
Sam wyglad programu wysylajacego syg do sterownika napisany jest w C# i dziala poprawnie. Nie wiem tylko jak teraz ten kod podczepić do buttona.
Poniżej przedstawiam kod wyslajacy syg do sterownika i widok kodu z przyciskiem:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
System.IO.Ports.SerialPort serialPort = new System.IO.Ports.SerialPort();
// Close the serial port if it is already open
if (serialPort.IsOpen)
{
serialPort.Close();
}
try
{
// Configure our serial port *** You'll likely need to change these for your config! ***
serialPort.PortName = "COM1";
serialPort.BaudRate = 115200;
serialPort.Parity = System.IO.Ports.Parity.None;
serialPort.DataBits = 8;
serialPort.StopBits = System.IO.Ports.StopBits.One;
//Now open the serial port
serialPort.Open();
}
catch (Exception ex)
{
Console.WriteLine("Couldn't open the Serial Port!");
Console.WriteLine(ex.ToString());//Report the actual error
}
try
{
//Now we'll send some data. Specifically we want to send "#Channel Number P1500<cr>" to center the servo
serialPort.Write("#1 P1500\r");
}
catch (Exception ex)
{
Console.WriteLine("Couldn't send the command for some reason... I give up. Sorry!");
Console.WriteLine(ex.ToString()); //Report the actual error
}
//Report our apparent success
Console.WriteLine("Center little servo, Center!" + Environment.NewLine);
Console.WriteLine("Sent: #1 P1500<cr>" + Environment.NewLine);
//Now let's close our serial port.
try
{
serialPort.Close();
}
catch (Exception ex)
{
Console.WriteLine("Couldn't close the darned serial port. Here's what it said: " + Environment.NewLine);
Console.WriteLine(ex.ToString());
}
//Wait for [Enter] before we close
Console.ReadLine();
}
}
}
Kod z przyciskiem:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
}
}
}