با سلام
من میخواستم که 1 برنامه برای کار با پرت کام تو net. بنویسم.البته تا حدودی این کار رو انجام دادم ولی با مشکلاتی روبرو شدم که از این قرار هست:
من با استفاده از کد زیر پرت رو باز میکنم و توش مینویسم البته پرت کام رو هم با یک کابل موس به 1 بردبورد وصل کردم که اگر جریان برقرار شد 1 ال ای دی روشن بشه.
تو 2 تا از این سیما همیشه جریان هست که شمارشون 3و7(یعنی پین 3 و 7) هست.سیم شماره 5 که گرند هست هم به برد وصله ولی سیم شماره 7 که باید اطلاعات از درون آن ارصال بشه هیچ تغییری نمیکنه.
حالا نمیدونم مشکل کد هست یا بردم؟ اگر میتوونید توو حل این مشکل کمکم کنید.
کد:using System;
using System.Data;
using System.Text;
using System.Drawing;
using System.IO.Ports;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using SerialPortTerminal.Properties;
namespace SerialPortTerminal
{
public enum DataMode { Text, Hex }
public enum LogMsgType { Incoming, Outgoing, Normal, Warning, Error };
public partial class frmTerminal : Form
{
private SerialPort comport = new SerialPort();
private Color[] LogMsgTypeColor = { Color.Blue, Color.Green, Color.Black, Color.Orange, Color.Red };
private bool KeyHandled = false;
/// <summary> Send the user's data currently entered in the 'send' box.</summary>
private void SendData()
{
if (CurrentDataMode == DataMode.Text)
{
//Create an ASCII encoding variable
Encoding ascii = Encoding.ASCII;
//Create an Unicode variable
Encoding unicode = Encoding.Unicode;
//Convert the string into a byte[]
byte[] unicodeBytes= unicode.GetBytes(txtSendData.Text);
//Perform the conversion from one encoding to the other
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
//Convert the new byte[] into a char[] and then into a string.
//This is a slightly different approach to converting to illustrate
//the use of GetCharCount/GetChars
char[] asciiChar = new char[ascii.GetCharCount(asciiBytes,0,asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChar, 0);
string sNEW = new string(asciiChar);
//Send the user's text straight out the port
comport.WriteLine(sNEW);
}
else
{
try
{
//Convert the user's string of hex digits (ex: B4 CA E2) to a byte array
byte[] data = HexStringToByteArray(txtSendData.Text);
//Send the binary data out the port
comport.Write(data, 0, data.Length);
}
} txtSendData.SelectAll();
}
}
}