实例介绍
【实例简介】 C# 电源电压电流上位机 源码
private const float VOLTAGE_MAX = 30.00f, CURRENT_MAX = 4.000f;
public enum MODE
{
MODE_VOLTAGE = 0x00,
MODE_CURRENT = 0x01,
}
private MODE currentMode = MODE.MODE_VOLTAGE;
//与下位机通讯相关
public enum COM_CMD
{
//M2S: master to slave cmd, S2M: slave to master
USART_M2S_Output = 0x01, //输出控制(默认关)
USART_M2S_Mode = 0x02, //输出模式切换(默认电压模式)
USART_M2S_SetVal = 0x03, //Master2Slave设置期望值:[1-4]:电压; [5-8]:电流
USART_M2S_Cal = 0x04, //进入校准模式(只在下位机开机前几秒内能够进入校准模式)
USART_M2S_StepAdd = 0x05, //步进加
USART_M2S_StepSub = 0x06, //步进减
USART_M2S_FAN = 0x07, //风扇控制:[1]0关;1开;2自动(默认)
USART_M2S_STATE = 0x08, //实时数据发送状态:[1]1发送数据 0停止发送
USART_M2S_GetVal = 0x09, //获取前一次的设定值
USART_S2M_PreVal = 0x0A, //Slave2Master返回前一次的设定值:[1-4]:电压值; [5-8]:电流值
USART_S2M_RealVal = 0x0B, //Slave2Master返回的实际值:[1-4]:电压值; [5-8]:电流值
USART_S2M_RealTemp= 0x0C, //Slave2Master返回温度值:[1-4]:当前温度值
}
private const byte USART_FRAMEHEAD = 0xAA, USART_FRAMETAIL = 0x55, USART_FRAMECTRL = 0xA5;
private long m_TotalRxLostPackages = 0; //记录总的丢包数
private long m_RxPackageDataCount = 0; //记录接收到的一帧的字节数
private const int m_MaxPackageSize = 4096; //一帧最大的字节数
private byte[] m_pRxBuf = new byte[m_MaxPackageSize]; //接收缓存
float voltageSet = 0.0f, currentSet = 0.0f, voltageGet = 0.0f, currentGet = 0.0f;
//绘图相关
public struct CurveStruct
{
public PointPairList pointList;//曲线数据
public Color lineColor;//曲线颜色
public SymbolType lineStyle;//线型
public string curveName;//名称
public LineItem curve; //曲线
public float scaleFactor;//比例系数
public byte lineWidth; //线宽
}
private Hashtable curveHashTable = new Hashtable();//用来保存所有的曲线
private GraphPane mGraphPane;
private long tickStart = 0;
double currentTime;
//double previousTime = 0;
CurveStruct mCurveStructVolSet = new CurveStruct();
CurveStruct mCurveStructVolGet = new CurveStruct();
CurveStruct mCurveStructCurSet = new CurveStruct();
CurveStruct mCurveStructCurGet = new CurveStruct();
//线程相关
private Queue<byte> receiveByteQueue = new Queue<byte>();//串口缓存队列
private Thread _dataParseThread = null; //解析串口接收数据线程
private bool _runDataParseThread = false; //决定接收线程是否退出
.
├── DC_POWER
│ ├── DC_POWER
│ │ ├── App.config
│ │ ├── DC_POWER.csproj
│ │ ├── Mainform.Designer.cs
│ │ ├── Mainform.cs
│ │ ├── Mainform.resx
│ │ ├── POWER_128.ico
│ │ ├── Program.cs
│ │ ├── Properties
│ │ │ ├── AssemblyInfo.cs
│ │ │ ├── Resources.Designer.cs
│ │ │ ├── Resources.resx
│ │ │ ├── Settings.Designer.cs
│ │ │ └── Settings.settings
│ │ ├── Resources
│ │ │ ├── btncheckoff1.png
│ │ │ ├── btncheckoff2.png
│ │ │ ├── btncheckoff3.png
│ │ │ ├── btncheckoff4.png
│ │ │ ├── btncheckoff5.png
│ │ │ ├── btncheckoff6.png
│ │ │ ├── btncheckon1.png
│ │ │ ├── btncheckon2.png
│ │ │ ├── btncheckon3.png
│ │ │ ├── btncheckon4.png
│ │ │ ├── btncheckon5.png
│ │ │ ├── btncheckon6.png
│ │ │ ├── shutdown.ico
│ │ │ ├── standby.ico
│ │ │ └── standby1.ico
│ │ ├── SlideButton.cs
│ │ ├── SlideButton.designer.cs
│ │ ├── SlideButton.resx
│ │ ├── bin
│ │ │ ├── Debug
│ │ │ │ ├── DC_POWER.exe
│ │ │ │ ├── DC_POWER.exe.config
│ │ │ │ ├── DC_POWER.pdb
│ │ │ │ ├── DC_POWER.vshost.exe
│ │ │ │ ├── DC_POWER.vshost.exe.config
│ │ │ │ ├── EnhancedGlassButton.dll
│ │ │ │ ├── ICON
│ │ │ │ │ ├── POWER_128.ico
│ │ │ │ │ ├── POWER_16.ico
│ │ │ │ │ ├── POWER_24.ico
│ │ │ │ │ ├── POWER_32.ico
│ │ │ │ │ ├── POWER_48.ico
│ │ │ │ │ ├── POWER_64.ico
│ │ │ │ │ ├── shutdown.ico
│ │ │ │ │ └── standby.ico
│ │ │ │ ├── Knob.dll
│ │ │ │ ├── LBIndustrialCtrls.dll
│ │ │ │ ├── Manometers.dll
│ │ │ │ ├── System.Windows.Forms.Ribbon35.dll
│ │ │ │ └── ZedGraph.dll
│ │ │ └── Release
│ │ │ ├── DC_POWER.exe
│ │ │ ├── DC_POWER.exe.config
│ │ │ ├── DC_POWER.pdb
│ │ │ ├── DC_POWER.vshost.exe
│ │ │ ├── DC_POWER.vshost.exe.config
│ │ │ ├── DC_POWER.vshost.exe.manifest
│ │ │ ├── EnhancedGlassButton.dll
│ │ │ ├── ICON
│ │ │ │ ├── POWER_128.ico
│ │ │ │ ├── POWER_16.ico
│ │ │ │ ├── POWER_24.ico
│ │ │ │ ├── POWER_32.ico
│ │ │ │ ├── POWER_48.ico
│ │ │ │ ├── POWER_64.ico
│ │ │ │ ├── shutdown.ico
│ │ │ │ └── standby.ico
│ │ │ ├── Knob.dll
│ │ │ ├── LBIndustrialCtrls.dll
│ │ │ ├── Manometers.dll
│ │ │ ├── System.Windows.Forms.Ribbon35.dll
│ │ │ └── ZedGraph.dll
│ │ └── obj
│ │ ├── Debug
│ │ │ ├── DC_POWER.Mainform.resources
│ │ │ ├── DC_POWER.Properties.Resources.resources
│ │ │ ├── DC_POWER.csproj.FileListAbsolute.txt
│ │ │ ├── DC_POWER.csproj.GenerateResource.Cache
│ │ │ ├── DC_POWER.csprojResolveAssemblyReference.cache
│ │ │ ├── DC_POWER.exe
│ │ │ ├── DC_POWER.pdb
│ │ │ ├── DesignTimeResolveAssemblyReferences.cache
│ │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ │ ├── TempPE
│ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ │ └── Release
│ │ ├── DC_POWER.Mainform.resources
│ │ ├── DC_POWER.Properties.Resources.resources
│ │ ├── DC_POWER.SlideButton.resources
│ │ ├── DC_POWER.csproj.FileListAbsolute.txt
│ │ ├── DC_POWER.csproj.GenerateResource.Cache
│ │ ├── DC_POWER.csprojResolveAssemblyReference.cache
│ │ ├── DC_POWER.exe
│ │ ├── DC_POWER.pdb
│ │ ├── DesignTimeResolveAssemblyReferences.cache
│ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ ├── TempPE
│ │ │ └── Properties.Resources.Designer.cs.dll
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DC_POWER.sln
│ ├── DC_POWER.v11.suo
│ ├── ICON
│ │ ├── POWER_128.ico
│ │ ├── POWER_16.ico
│ │ ├── POWER_24.ico
│ │ ├── POWER_32.ico
│ │ ├── POWER_48.ico
│ │ ├── POWER_64.ico
│ │ ├── shutdown.ico
│ │ └── standby.ico
│ └── SlideButton
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── Resources
│ │ ├── btncheckoff1.png
│ │ ├── btncheckoff2.png
│ │ ├── btncheckoff3.png
│ │ ├── btncheckoff4.png
│ │ ├── btncheckoff5.png
│ │ ├── btncheckoff6.png
│ │ ├── btncheckon1.png
│ │ ├── btncheckon2.png
│ │ ├── btncheckon3.png
│ │ ├── btncheckon4.png
│ │ ├── btncheckon5.png
│ │ └── btncheckon6.png
│ ├── SlideButon.Designer.cs
│ ├── SlideButon.cs
│ ├── SlideButton.csproj
│ ├── bin
│ │ ├── Debug
│ │ └── Release
│ │ ├── SlideButton.dll
│ │ └── SlideButton.pdb
│ └── obj
│ ├── Debug
│ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ ├── TempPE
│ │ │ └── Properties.Resources.Designer.cs.dll
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ └── Release
│ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ ├── SlideButton.Properties.Resources.resources
│ ├── SlideButton.csproj.FileListAbsolute.txt
│ ├── SlideButton.csproj.GenerateResource.Cache
│ ├── SlideButton.dll
│ ├── SlideButton.pdb
│ ├── TempPE
│ │ └── Properties.Resources.Designer.cs.dll
│ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
└── [图] C# 电源电压电流上位机 串口源码,rs232.rar
26 directories, 141 files
【实例截图】
【核心代码】
public partial class Mainform : Form
{private const float VOLTAGE_MAX = 30.00f, CURRENT_MAX = 4.000f;
public enum MODE
{
MODE_VOLTAGE = 0x00,
MODE_CURRENT = 0x01,
}
private MODE currentMode = MODE.MODE_VOLTAGE;
//与下位机通讯相关
public enum COM_CMD
{
//M2S: master to slave cmd, S2M: slave to master
USART_M2S_Output = 0x01, //输出控制(默认关)
USART_M2S_Mode = 0x02, //输出模式切换(默认电压模式)
USART_M2S_SetVal = 0x03, //Master2Slave设置期望值:[1-4]:电压; [5-8]:电流
USART_M2S_Cal = 0x04, //进入校准模式(只在下位机开机前几秒内能够进入校准模式)
USART_M2S_StepAdd = 0x05, //步进加
USART_M2S_StepSub = 0x06, //步进减
USART_M2S_FAN = 0x07, //风扇控制:[1]0关;1开;2自动(默认)
USART_M2S_STATE = 0x08, //实时数据发送状态:[1]1发送数据 0停止发送
USART_M2S_GetVal = 0x09, //获取前一次的设定值
USART_S2M_PreVal = 0x0A, //Slave2Master返回前一次的设定值:[1-4]:电压值; [5-8]:电流值
USART_S2M_RealVal = 0x0B, //Slave2Master返回的实际值:[1-4]:电压值; [5-8]:电流值
USART_S2M_RealTemp= 0x0C, //Slave2Master返回温度值:[1-4]:当前温度值
}
private const byte USART_FRAMEHEAD = 0xAA, USART_FRAMETAIL = 0x55, USART_FRAMECTRL = 0xA5;
private long m_TotalRxLostPackages = 0; //记录总的丢包数
private long m_RxPackageDataCount = 0; //记录接收到的一帧的字节数
private const int m_MaxPackageSize = 4096; //一帧最大的字节数
private byte[] m_pRxBuf = new byte[m_MaxPackageSize]; //接收缓存
float voltageSet = 0.0f, currentSet = 0.0f, voltageGet = 0.0f, currentGet = 0.0f;
//绘图相关
public struct CurveStruct
{
public PointPairList pointList;//曲线数据
public Color lineColor;//曲线颜色
public SymbolType lineStyle;//线型
public string curveName;//名称
public LineItem curve; //曲线
public float scaleFactor;//比例系数
public byte lineWidth; //线宽
}
private Hashtable curveHashTable = new Hashtable();//用来保存所有的曲线
private GraphPane mGraphPane;
private long tickStart = 0;
double currentTime;
//double previousTime = 0;
CurveStruct mCurveStructVolSet = new CurveStruct();
CurveStruct mCurveStructVolGet = new CurveStruct();
CurveStruct mCurveStructCurSet = new CurveStruct();
CurveStruct mCurveStructCurGet = new CurveStruct();
//线程相关
private Queue<byte> receiveByteQueue = new Queue<byte>();//串口缓存队列
private Thread _dataParseThread = null; //解析串口接收数据线程
private bool _runDataParseThread = false; //决定接收线程是否退出
.
├── DC_POWER
│ ├── DC_POWER
│ │ ├── App.config
│ │ ├── DC_POWER.csproj
│ │ ├── Mainform.Designer.cs
│ │ ├── Mainform.cs
│ │ ├── Mainform.resx
│ │ ├── POWER_128.ico
│ │ ├── Program.cs
│ │ ├── Properties
│ │ │ ├── AssemblyInfo.cs
│ │ │ ├── Resources.Designer.cs
│ │ │ ├── Resources.resx
│ │ │ ├── Settings.Designer.cs
│ │ │ └── Settings.settings
│ │ ├── Resources
│ │ │ ├── btncheckoff1.png
│ │ │ ├── btncheckoff2.png
│ │ │ ├── btncheckoff3.png
│ │ │ ├── btncheckoff4.png
│ │ │ ├── btncheckoff5.png
│ │ │ ├── btncheckoff6.png
│ │ │ ├── btncheckon1.png
│ │ │ ├── btncheckon2.png
│ │ │ ├── btncheckon3.png
│ │ │ ├── btncheckon4.png
│ │ │ ├── btncheckon5.png
│ │ │ ├── btncheckon6.png
│ │ │ ├── shutdown.ico
│ │ │ ├── standby.ico
│ │ │ └── standby1.ico
│ │ ├── SlideButton.cs
│ │ ├── SlideButton.designer.cs
│ │ ├── SlideButton.resx
│ │ ├── bin
│ │ │ ├── Debug
│ │ │ │ ├── DC_POWER.exe
│ │ │ │ ├── DC_POWER.exe.config
│ │ │ │ ├── DC_POWER.pdb
│ │ │ │ ├── DC_POWER.vshost.exe
│ │ │ │ ├── DC_POWER.vshost.exe.config
│ │ │ │ ├── EnhancedGlassButton.dll
│ │ │ │ ├── ICON
│ │ │ │ │ ├── POWER_128.ico
│ │ │ │ │ ├── POWER_16.ico
│ │ │ │ │ ├── POWER_24.ico
│ │ │ │ │ ├── POWER_32.ico
│ │ │ │ │ ├── POWER_48.ico
│ │ │ │ │ ├── POWER_64.ico
│ │ │ │ │ ├── shutdown.ico
│ │ │ │ │ └── standby.ico
│ │ │ │ ├── Knob.dll
│ │ │ │ ├── LBIndustrialCtrls.dll
│ │ │ │ ├── Manometers.dll
│ │ │ │ ├── System.Windows.Forms.Ribbon35.dll
│ │ │ │ └── ZedGraph.dll
│ │ │ └── Release
│ │ │ ├── DC_POWER.exe
│ │ │ ├── DC_POWER.exe.config
│ │ │ ├── DC_POWER.pdb
│ │ │ ├── DC_POWER.vshost.exe
│ │ │ ├── DC_POWER.vshost.exe.config
│ │ │ ├── DC_POWER.vshost.exe.manifest
│ │ │ ├── EnhancedGlassButton.dll
│ │ │ ├── ICON
│ │ │ │ ├── POWER_128.ico
│ │ │ │ ├── POWER_16.ico
│ │ │ │ ├── POWER_24.ico
│ │ │ │ ├── POWER_32.ico
│ │ │ │ ├── POWER_48.ico
│ │ │ │ ├── POWER_64.ico
│ │ │ │ ├── shutdown.ico
│ │ │ │ └── standby.ico
│ │ │ ├── Knob.dll
│ │ │ ├── LBIndustrialCtrls.dll
│ │ │ ├── Manometers.dll
│ │ │ ├── System.Windows.Forms.Ribbon35.dll
│ │ │ └── ZedGraph.dll
│ │ └── obj
│ │ ├── Debug
│ │ │ ├── DC_POWER.Mainform.resources
│ │ │ ├── DC_POWER.Properties.Resources.resources
│ │ │ ├── DC_POWER.csproj.FileListAbsolute.txt
│ │ │ ├── DC_POWER.csproj.GenerateResource.Cache
│ │ │ ├── DC_POWER.csprojResolveAssemblyReference.cache
│ │ │ ├── DC_POWER.exe
│ │ │ ├── DC_POWER.pdb
│ │ │ ├── DesignTimeResolveAssemblyReferences.cache
│ │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ │ ├── TempPE
│ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ │ └── Release
│ │ ├── DC_POWER.Mainform.resources
│ │ ├── DC_POWER.Properties.Resources.resources
│ │ ├── DC_POWER.SlideButton.resources
│ │ ├── DC_POWER.csproj.FileListAbsolute.txt
│ │ ├── DC_POWER.csproj.GenerateResource.Cache
│ │ ├── DC_POWER.csprojResolveAssemblyReference.cache
│ │ ├── DC_POWER.exe
│ │ ├── DC_POWER.pdb
│ │ ├── DesignTimeResolveAssemblyReferences.cache
│ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ ├── TempPE
│ │ │ └── Properties.Resources.Designer.cs.dll
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DC_POWER.sln
│ ├── DC_POWER.v11.suo
│ ├── ICON
│ │ ├── POWER_128.ico
│ │ ├── POWER_16.ico
│ │ ├── POWER_24.ico
│ │ ├── POWER_32.ico
│ │ ├── POWER_48.ico
│ │ ├── POWER_64.ico
│ │ ├── shutdown.ico
│ │ └── standby.ico
│ └── SlideButton
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── Resources
│ │ ├── btncheckoff1.png
│ │ ├── btncheckoff2.png
│ │ ├── btncheckoff3.png
│ │ ├── btncheckoff4.png
│ │ ├── btncheckoff5.png
│ │ ├── btncheckoff6.png
│ │ ├── btncheckon1.png
│ │ ├── btncheckon2.png
│ │ ├── btncheckon3.png
│ │ ├── btncheckon4.png
│ │ ├── btncheckon5.png
│ │ └── btncheckon6.png
│ ├── SlideButon.Designer.cs
│ ├── SlideButon.cs
│ ├── SlideButton.csproj
│ ├── bin
│ │ ├── Debug
│ │ └── Release
│ │ ├── SlideButton.dll
│ │ └── SlideButton.pdb
│ └── obj
│ ├── Debug
│ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ ├── TempPE
│ │ │ └── Properties.Resources.Designer.cs.dll
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ └── Release
│ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ ├── SlideButton.Properties.Resources.resources
│ ├── SlideButton.csproj.FileListAbsolute.txt
│ ├── SlideButton.csproj.GenerateResource.Cache
│ ├── SlideButton.dll
│ ├── SlideButton.pdb
│ ├── TempPE
│ │ └── Properties.Resources.Designer.cs.dll
│ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
└── [图] C# 电源电压电流上位机 串口源码,rs232.rar
26 directories, 141 files
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论