Morgen Leute, ich habe ein Problem und zwar habe ich in meiner C# WPF Projektmappe zwei Projekte. In einem Projekt bekomme ich Koordinaten aus der Hardware ausgelesen die ich in meinem Projekt benötige. Ich initialisiere meine variablen mit = 0 und der übertragene Wert ist auch 0. Wenn ich mit anderen Werten initialisiere bekomme ich auch diese übertragen. Allerdings werden in diesen Variablen die Koordinaten gespeichert die auch richtig in der Console ausgegeben werden. Ich bekomme aber nur die Werte übertragen mit dem ich die variablen initialisiert habe. Hier mal mein code.
1 | public class Program |
2 | {
|
3 | static void Main(string[] args) |
4 | {
|
5 | DeviceConfiguration DeviceConfiguration = new DeviceConfiguration(); |
6 | |
7 | DeviceConfiguration.ServiceUrl = "http://.........../"; |
8 | |
9 | Device Device = new Device(DeviceConfiguration); |
10 | |
11 | Device.StartThread(true); |
12 | |
13 | Device.NewDataAvailableEvent += Device_NewDataAvailableEvent; |
14 | |
15 | |
16 | Console.ReadKey(); |
17 | }
|
18 | |
19 | private static double lastPosX = 0; |
20 | private static double lastPosY = 0; |
21 | private static double lastPosZ = 0; |
22 | |
23 | private static void Device_NewDataAvailableEvent(Position.SignedPositions signedPositions) |
24 | {
|
25 | try { |
26 | if (signedPositions.Positions != null) |
27 | {
|
28 | if (signedPositions.Positions.Count() > 1) |
29 | {
|
30 | lastPosX = signedPositions.Positions[1].X; |
31 | lastPosY = signedPositions.Positions[1].Y; |
32 | lastPosZ = signedPositions.Positions[1].Z; |
33 | |
34 | Console.WriteLine(signedPositions.Positions[1].ChannelIndex + " " + lastPosX + " " + lastPosY + " " + lastPosZ); |
35 | }
|
36 | }
|
37 | }
|
38 | catch (Exception) |
39 | {
|
40 | |
41 | }
|
42 | }
|
43 | |
44 | public static Point3D getpositionData() |
45 | {
|
46 | Point3D returnPoint = new Point3D(-9999,-9999,-9999); |
47 | |
48 | |
49 | returnPoint.X = lastPosX; |
50 | returnPoint.Y = lastPosY; |
51 | returnPoint.Z = lastPosZ; |
52 | |
53 | return returnPoint; |
54 | }
|
55 | }
|
In meinem Projekt habe ich den Namespace bei den header hinzugefügt und rufe wie folgt die getpositionData Methode auf.
1 | private void Position() |
2 | {
|
3 | Point3D coordinates = Program.getpositionData(); |
4 | try
|
5 | {
|
6 | if (!Dispatcher.CheckAccess()) |
7 | {
|
8 | textBox21.Dispatcher.BeginInvoke(new Action(() => PositionSar())); |
9 | textBox22.Dispatcher.BeginInvoke(new Action(() => PositionSar())); |
10 | textBox23.Dispatcher.BeginInvoke(new Action(() => PositionSar())); |
11 | }
|
12 | |
13 | else
|
14 | {
|
15 | textBox21.Text = coordinates.X.ToString(); |
16 | textBox22.Text = coordinates.Y.ToString(); |
17 | textBox23.Text = coordinates.Z.ToString(); |
18 | }
|
19 | }
|
20 | catch (Exception ex) |
21 | {
|
22 | MessageBox.Show(ex.Message); |
23 | }
|
24 | }
|
Ich bekomme leider nur die 3 initialisierten nullen bei mir in der Oberfläche angezeigt. Jemand eine idee oder einen ansatz??