using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using RJCP.IO.Ports; using WIDESEA_ISerialPortRepository; using WIDESEA_ISerialPortService; using WIDESEA_SerialPortTestService; using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseServices; using WIDESEAWCS_Model.Models.SerialPort; namespace WIDESEA_SerialPortService { public class SerialPortService : ServiceBase, ISerialPortService { private SerialPortTestService _serialPortTestService; // 串口服务 public SerialPortService(ISerialPortRepository BaseDal) : base(BaseDal) { //_serialPortTestService = new SerialPortTestService("COM3"); // 传递 SerialPortService 到 SerialPortTestService _serialPortTestService = new SerialPortTestService("COM3", this); } public WebResponseContent AddSerialPort(Dt_TorqueOp TorqueOp) { WebResponseContent content = new WebResponseContent(); //BaseDal.Db.Insertable(TorqueOp).ExecuteCommand(); BaseDal.AddData(TorqueOp); content = WebResponseContent.Instance.OK("成功"); return content; } // 启动串口通信 public void StartSerialPortCom() { //WebResponseContent content = new WebResponseContent(); // 打开串口并开始发送数据 _serialPortTestService.OpenSerialPort(); //return content; } // 停止串口通信 public void StopSerialPortCom() { //WebResponseContent content = new WebResponseContent(); _serialPortTestService.CloseSerialPort(); // 关闭串口 //return content; } public List GetSerialPortCom() { return _serialPortTestService.GetReceivedData(); } } }