Autor Beitrag
tomycat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Do 27.04.23 11:45 
hallo,
ich will NUR auf dem Comport 5 eine Zeichenkette 1234 senden.

Mein Muster: SerialPort

Mein Projekt mit Konsole C# mit VS 2019
Alles Original, von meinem Muster ...
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
using System;
using System.IO.Ports;
using System.Threading;

public class SerialPort : System.ComponentModel.Component 
{ }

public class PortChat
{
    static bool _continue;
    static SerialPort _serialPort;

    public static void Main()
    {
        string name;
        string message;
        StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
        Thread readThread = new Thread(Read);

        // Create a new SerialPort object with default settings.
        _serialPort = new SerialPort();

        // Allow the user to set the appropriate properties.
        _serialPort.PortName = SetPortName(_serialPort.PortName);  /////// Portname ist rot ?!?!
................schnipp.........

Zitat:
SerialPort enthält keine Definition für PortName.


Moderiert von user profile iconTh69: URL-Titel hinzugefügt
Moderiert von user profile iconTh69: C#-Tags hinzugefügt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19273
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 27.04.23 11:59 
user profile icontomycat hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
public class SerialPort : System.ComponentModel.Component 
{ }

public class PortChat
{
    static bool _continue;
    static SerialPort _serialPort;

Die Deklaration von SerialPort ist dort nur zur Information vorhanden. Wenn du die bei dir einfügst, legst du eine neue leere Klasse an. Die enthält dann auch nicht PortName.

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Do 27.04.23 13:44 
thx,
sorry, bin auf dem Schlauch, was soll ich einfügen jetzt?
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4701
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Do 27.04.23 14:32 
Nicht einfügen du sollst etwas wegnehmen.
Am Anfang deines Codes hast du das hier eingefügt

ausblenden C#-Quelltext
1:
2:
public class SerialPort : System.ComponentModel.Component 
{ }


Das musst du wegmachen. Damit hast du eine neue "SerialPort" Klasse erfunden und die kann nichts wie du festgestellt hast. Die SerialPort Klasse gibt es schon im Framework und die existierende möchtest du benutzen. Die ist momentan von deiner überdeckt und der Compiler findet die falsche deine neu erzeugte Klasse.

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Mi 03.05.23 14:11 
thx,

sooo habs weggenommen.
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
using System;
using System.IO.Ports;
using System.Threading;

public class PortChat
{
    static bool _continue;
    static SerialPort _serialPort; ////////////////// SerialPort <--- ist ROT

    public static void Main()
    {
        string name;
        string message;
        StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
        Thread readThread = new Thread(Read);

        // Create a new SerialPort object with default settings.
        _serialPort = new SerialPort(); ////////////////// SerialPort <--- ist ROT

        // Allow the user to set the appropriate properties.
        _serialPort.PortName = SetPortName(_serialPort.PortName);

-----------------schnipp-----------------------


Das rot hinterlegte:
Der Typname"SerialPort" konnte nicht im Namesspace "System.IO.Ports" gefunden werden. Dieser Tpe wurde an Assembly "System.IO.Ports,Version4.0.1.0 Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51 weitergeleitet. Sie sollten einen Verweis auf die Assembly hinzufügen.

Mit dem Form1 Projekt C# habe ich es hinbekommen.
Ich brauche aber den Comport unter der Konsolen App

Leider finde ich kein Assembly
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 03.05.23 14:48 
Binde System.IO.Ports (entsprechend der von dir verwendeten .NET Version) per NuGet ein.

Für diesen Beitrag haben gedankt: tomycat